I send an Ajax call to a PHP file, Then an array is returned.
I want to check the values of the returned data.
Here is the Javascript/jQuery code:
$.ajax({
url: "file.php",
type: "POST",
data: {'num': 12},
dataType : "json",
success: function(data){
JSON.parse(data);
console.log(data.status);
}
});
PHP code:
$status = 1;
$msg = 'Test message';
$response = array($status, $msg);
echo json_encode($response);
But I'm getting an error JSON.parse: unexpected non-whitespace character
JSON.parse(data)from your JS code. jQuery will already have deserialised it for youconsole.log(data.status);returnsundefinedconsole.log(data)output?