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」}] 謝謝! –