I have this ajax request that give me back:
Syntax Error unexpected end of input ajax
$.ajax({
url: "file.php",
type: 'POST',
dataType: "json",
data: {
string : name
},
success: function(data, textStatus, xhr) {
toastr.success(data, "Ok");
},
error: function(xhr, textStatus, errorThrown) {
toastr.error("Error: " + xhr + " error thrown: " + errorThrown+ " error " + errorThrown, "Error");
}
});
file.php is this one:
$string_to_found = $_POST['string'];
$file_xml = "../file.xml";
if (!file_exists($file_xml)) {
echo json_encode(array("response" => "no_file", "message"=>"File Not Found"));
} else {
$xml = simplexml_load_file($file_xml );
$number = count($xml);
for ($num = 0; $num < $number; $num++) {
$row++;
$filearray[] = array(
"cod" => (string)$xml->record[$num]->value,
"com" => (string)$xml->record[$num]->name,
);
}
foreach($filearray as $item){
if($item['com'] == $string_to_found ) {
echo json_encode(array("response" => "ok", "message"=>"Code Found", "code" => $item['cod']));
}
}
}
The file.php give me back this correct value:
{"response":"ok","message":"Code Found","cod":"AA019"}
How i can fix this problem? I trying to change in php print with echo and also change dataType and contentType