I've searched a lot for this but the answers that I find doesn't work but I think that the problem is mine.
JavaScript:
$.ajax({
type: 'POST',
url: url,
data: data,
dataType: 'json',
success: function(response) {
if(response.status == true) {
alert('ok');
} else {
alert('error');
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "
Error:" + err);
}
});
PHP
if(User::addFavLater($id, $user, 'favs')) {
$result = array("status" => true);
} else {
$result = array("status" => false);
}
header('Content-type: application/json');
echo json_encode($result);
So, this is an excerpt of code that I have and I think can you realising. I want PHP to send a JSON response into JavaScript but this is not happening and JavaScript gives me this error:
parsererror / SyntaxError: Unexpected token <
I'm using the 2.1.1 version of JQuery.
P.S.: Sorry for my english.