[英]Is it possible to abort jquery $.ajax request with data type json?
我想在窗口unload
事件中取消數據類型為json的jquery $.ajax
呼叫請求。 我嘗試這樣做,它在xhr.abort();
上xhr.abort();
錯誤xhr.abort();
線。
var xhr = $.ajax({
type: "POST",
url: serviceUrl,
dataType: "text json",
data: ajaxParameters,
async: true,
contentType: "application/json; charset=utf-8",
error: function(request, status, error) {
},
complete: function(e, xhr, settings) {
}
});
$(window).onunload = function(){
xhr.abort();
}
試試看...
// Global variable
var xhr;
xhr = $.ajax({
type: "POST",
url: serviceUrl,
dataType: "text json",
data: ajaxParameters,
async: true,
contentType: "application/json; charset=utf-8",
error: function(request, status, error) {
},
complete: function(e, xhr, settings) {
}
});
$('body').on('beforeunload',function(){
xhr.abort();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.