我一直在試圖讓AJAX調用在IE9中正常工作。我可以在網絡數據中看到請求順利通過。 jQuery $ .ajax()調用返回的jqXHR對象包含響應數據。然而,我的成功/錯誤/完整回調並不是解僱。下面的代碼...jQuery Ajax成功/錯誤回調沒有在IE中觸發
在我的腳本的頂部:
// override xhr for browser that use XDR
if ('XDomainRequest' in window && window.XDomainRequest !== null) {
// override default jQuery transport for IE
jQuery.ajaxSettings.xhr = function() {
try { return new XDomainRequest(); }
catch(e) {
console.log('test');
}
};
// Maybe a 304 response is causing the callbacks not to fire?
// This makes sure I'm getting 200
jQuery.ajaxSettings.cache = false;
// also, override the support check
jQuery.support.cors = true;
}
然後我Ajax調用...漂亮的平原。
$.ajax({
url: url,
success: success,
complete: complete,
beforeSend: beforeSend,
error: error
});
function success(response, textStatus, jqXHR){
console.log('success');
if(typeof fn == 'function'){
fn(response.data);
} else {
console.log('Invalid callback supplied for dataGateway');
}
}
function error(jqXHR, textStatus, errorThrown){
console.log("Could not retrieve data from API.");
return;
}
function complete(jqXHR, textStatus){
console.log('complete');
}
// This is the only callback that gets fired
function beforeSend(jqXHR, settings){
console.log('before send');
}
有沒有人知道如何解決這個問題?