我無法獲得這個$ .ajax函數在Chrome中工作。當我發出ajax請求時,永遠不會返回響應。當我在Chrome開發工具中查看它時,它表示json請求仍在等待處理。到目前爲止,我已經找到了將這些參數添加到選項的建議。爲什麼這個jQuery ajax調用工作在Chrome中
'{類型: 「郵報」 的數據: '',緩存:假的,異步:假}'
然而,所有的這些選項使它工作。
try {
var o = {username: 'adobeedge', count: 4};
var twitterUrl = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + o.username + '&count=' + o.count;
$("body").append('<p>attempting ajax</p>');
$.ajax({url: twitterUrl,
dataType: 'jsonp',
type: "post",
data: '',
cache: false,
async: false,
})
.success(function(data) {
$.each(data, function(index, item) {
$("body").append(item.text);
});
}) ;
}
catch (error) {
alert("Error: " + error.toString());
}
您是否看過開發工具中的請求/響應以查看可能發生了什麼?控制檯中是否有錯誤? –
你能比「不起作用」更具體嗎?它是失敗還是你獲得了你不期望的結果?任何錯誤消息或HTTP代碼? –
適用於我...查看http://jsfiddle.net/vLYmY/3/ –