[英]Is it possible to abort jquery $.ajax request with data type json?
I want cancel jquery $.ajax
call request with datatype json on window unload
event. 我想在窗口unload
事件中取消数据类型为json的jquery $.ajax
呼叫请求。 I tried doing this and it is throwing error on xhr.abort();
我尝试这样做,它在xhr.abort();
上xhr.abort();
错误xhr.abort();
line. 线。
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();
}
Try this out... 试试看...
// 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.