OK [编号],我已搜查了这个问题,并发现它无数的答案,但没有为我工作。 我越来越jQuery21006460414978209883_1395689439888被称为错误。 AJAX调用是正确的,状态是200和我试图调用的php url,我已经验证了它的JSON,它是根据jsonlint的有效json。 我使用jsonp,因为它是跨域调用。 任何意见都会帮助我调试。 这里是我的javascript代码:jQuery的不叫
$.ajax({
crossDomain: true,
cache: false,
type: "GET",
url: "http://example.com/backend.php",
data: "fdaf",
//async: false,
dataType: "jsonp",
contentType: 'application/json; charset=utf-8',
success: function(msg){
alert("success"+ JSON.stringify(msg));
},
error:function (xhr, ajaxOptions, thrownError){
alert('error function status is : '+xhr.status);
alert('error thrown is: '+thrownError);
},
jsonp: "callback",
complete: function (requestState) {
alert("working");
}
});
我backend.php代码是在这里:
<?php
header('Content-Type: application/json');
$arr = array('a' => "1", 'b' => "2", 'c' => "3", 'd' => "4");
$tr = json_encode($arr);
echo $_GET['callback'].'['.$tr.']';
?>
请指教一下我做错了这里。非常感谢!
你看到的确切错误是什么,你在哪里看到它? –
@MikeC我收到这个错误,马上进入错误功能。抛出的错误是:错误:jQuery210012445046612992883_1395690899125不叫 –
@adeneo好了,可以请让我知道我在做什么错在这里。这里是backend.php的[{“a”的输出:“1”,“B”: “2”,“c”:“3”,“d”:“4”}] 谢谢! –