I need some help here. I'm sending simple request to server, and the return I expected is JSON as data type. But when I checked in development tools console log I get "parsererror SyntaxError {}" and "parsererror".
How can I make this right? Below is the code.
JQuery
$(':submit').live('click', function() {
$.ajax({
type : 'post',
url: 'testJSON.php',
beforeSend:console.log('sending...'),
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(data){
console.log(data.status);
// do magic
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
},
complete: function(XMLHttpRequest, status) {
console.log(status);
}
});
return false;
});
and this is the testJSON.php
<?php
$data = array(
"status" => 1,
"firstname" => "foo",
"lastname" => "bar",
);
header('Content-type: application/json; charset=utf-8" ');
echo json_encode($data);
exit();
?>
FYI I use the latest version of WAMP. Any help very much appreciated.
parsererrorwhen parsing JSON... Sorry if I misunderstood.testJSON.phpas UTF-8 with BOM or without BOM?