I am using a PHP script to create JSON data. It looks like this:
{"Id":0}
Now if I put that into a file and then load it using ajax it's fine. But if I request this from the PHP script I get
parsererror | SyntaxError: Unexpected token ILLEGAL
Here is the code that I am using to load the JSON from the PHP:
$.ajax({
url: 'check.php',
data: {
username: 'LOL',
password: '1234'
},
dataType: 'json',
type: 'POST',
success: function(data) {
$('#result').html('#Id=' + data.Id);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#result').html(textStatus + ' | ' + errorThrown);
}
});
Here is the PHP code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
echo '{"Id":0}';
?>
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…