i have the below error for this code “echo json_encode($returnArray);”"unexpected non-whitespace character after JSON data at line 1 column 38 of the JSON data"help me out to fix this.
Thank you.
This might help? https://discourse.hkvstore.com/t/export-syntaxerror-unexpected-non-whitespace-character-after-json-at-position-4/7850/1
$.ajax({
type: "POST",
url: "Custompage", // data send to Custompage page
dataType: "json",
data: 'fgh_wh_for_so=' + warehouse + '&fgh_prj_for_so=' + split_prjID[0],
cache:false,
success:
function(data){
if (data == 0) {
alert("Connection denied from ERP. Contact to PHP Team");
return false;
}
else if (data == 1) {
alert("Project ID not found in ERP - "+whcode+" WH.");
return false;
}
else if (data == 2) {
// alert("SO Reference not found in ERP - "+whcode+" WH for Project ID :"+split_prjID[0]+".\nSO Reference status should not be Entered or Closed.");
alert("SO reference is not found. Please verify the below criteria in ERP.\n1. SO status should not be entered/closed.\n2. Project ID ("+split_prjID[0]+") should be mapped to the SO.");
return false;
}
else {
$("#dialog").dialog(); //open product list popup window
$("#dialog").animate({ height: 250}, 600); //specifying pop up window height
$("#dialog").dialog( "option", "width", 300);
$("#dialog").empty();
$("#dialog").dialog({ title: "SO Reference"});
for (var i = 0; i < data.length; i++)
{
// var splitDtata = data[i].split("__");
$("#dialog").append('<tr class="fglist"><td><a id=' + '"'+data[i]+'"' + ' class="fgName" onclick="getUserSelected_details(this, ' + soref_controlID +')" name=' + '"'+data[i]+'"' + '>'+data[i]+'</a></td></tr><tr></tr>');
}
}
},
error: function(xhr, status, error) {
// Handle the error, for example, log it
console.error('Error:', status, error);
}
});
this is my code.in custom page i am returning the array after “echo json_encode($array);” this line i written “return $array;”
sakthimano wrote:
in custom page i am returning the array after “echo json_encode($array);” this line i written “return $array;”
You may post your server side code in the custom page for discussion.Also read Check HTTP Response.
Custom page code :
if ($connect) {
$returnArray = array();
/* $get_wh_id = oci_parse($connect, "SELECT WAREHOUSEID FROM SCMWAREHOUSE WHERE WAREHOUSECODE = '$fgh_wh_for_soref'");
oci_execute($get_wh_id);
while (($row = oci_fetch_row($get_wh_id)) != false) {
$selected_wh_id = $row[0];
}
oci_free_statement($get_wh_id); */
$get_prj_id = oci_parse($connect, "SELECT PROJECTID FROM POSPROJECT WHERE PROJECTNUMBER = '$fgh_prj_for_soref' AND WAREHOUSEID = '$selected_wh_id'");
oci_execute($get_prj_id);
$selected_prj_id = NULL;
while (($row = oci_fetch_row($get_prj_id)) != false) {
$selected_prj_id = $row[0];
}
oci_free_statement($get_prj_id);
if (strlen($selected_prj_id) > 0) {
$get_soreference = oci_parse($connect, "SELECT ALTERNATEORDERNUMBER FROM POSHEADERS WHERE WAREHOUSEID = '$selected_wh_id' AND PROJECTID = '$selected_prj_id' AND STATUS NOT IN ('ENTERED','CLOSED') AND ALTERNATEORDERNUMBER NOT LIKE '%FO%'");
oci_execute($get_soreference);
$validate_flag = 0;
while (($row = oci_fetch_row($get_soreference)) != false) {
$so_reference = addslashes($row[0]);
array_push($returnArray, $so_reference);
$validate_flag++;
}
oci_free_statement($get_soreference);
if ($validate_flag == 0)
$returnArray = 2;
}
else
$returnArray = 1;
}
else
{
$returnArray = 0;
}
echo json_encode($returnArray);
return($returnArray);
}
sakthimano wrote:
“unexpected non-whitespace character after JSON data at line 1 column 38 of the JSON data”
That means the HTTP response is not JSON.arbei wrote:
Also read > Check HTTP Response> .
If your “custom page” is a Custom File, you should put your code in the Page_Load server event, not in the page content, and you should use exit() at the end of your code so that no other code than your own JSON will be outputted. In fact, if you are using Custom File, you should consider using Route_Action server event instead.
If i use that custom file only for server side events mean i have to add anything in content??
arbei wrote:
If your “custom page” is a > Custom File> , you should put your code in the > Page_Load > server event, > NOT > in the page content.> If your “custom page” is a > Custom File> , you should consider using > Route_Action > server event instead.
Note: If your “custom page” is a standalone .php of your own, and it is NOT a PHPMaker Custom File, above comments do not apply.
Thanks.
now i want one solution for the below question.
In standalone php file how can i get current user id?
If it is your own standalone .php file, you are on your own, you cannot use the PHPMaker functions such as CurrentUserID(). That’s why I suggested:
you should consider using > Route_Action > server event instead.
I don’t want to display the page of custom file. Without route_action how to get ajax call with json response?i am talking about through php maker created custom file.Why i got only html response?
arbei wrote:
If your “custom page” is a > Custom File> , you should put your code in the Page_Load server event, > not > in the page content, and you should use > exit() > at the end of your code so that no other code than your own JSON will be outputted.