Javascript AJAX在中止()onPopstate后停止工作
如果用户单击前进/后退按钮时出现未完成的AJAX调用,我将使用以下代码来中止()。中止调用非常有效,但此后对函数的后续调用将不起作用。当我尝试在中止后调用swapContent()时,它什么也不做。中止后如何再次调用AJAX函数 全球Javascript AJAX在中止()onPopstate后停止工作,javascript,jquery,ajax,abort,popstate,Javascript,Jquery,Ajax,Abort,Popstate,如果用户单击前进/后退按钮时出现未完成的AJAX调用,我将使用以下代码来中止()。中止调用非常有效,但此后对函数的后续调用将不起作用。当我尝试在中止后调用swapContent()时,它什么也不做。中止后如何再次调用AJAX函数 全球 var ajax; var ajax; AJAX function swapContent() { ajax = $.ajax({ type: 'GET', data: params, url: 'co
var ajax;
var ajax;
AJAX
function swapContent() {
ajax = $.ajax({
type: 'GET',
data: params,
url: 'content.php',
success: function(data) {
$('#browser').html(data);
},
error:function(e){
// Error
}
});
}
function swapContent() {
ajax = $.ajax({
type: 'GET',
data: params,
url: 'content.php',
// -- VERIFY AJAX IS NULL -- //
beforeSend : function() {
if(ajax != null) {
ajax.abort(); // ABORT IF NOT NULL
}
},
success: function(data) {
$('#browser').html(data);
ajax = null; // NULL AJAX ON SUCCESS
},
error:function(e){
// Error
}
});
}
onPopstate
$(window).on('popstate', function() {
// Abort active requests
if(ajax && ajax.readystate != 4){
ajax.abort();
}
});
$(window).on('popstate', function() {
if(ajax && ajax.readystate != 4){
ajax.abort();
ajax = null; // NULL AFTER ABORT
}
});
将ajax设置回null:
$(window).on('popstate', function() {
if(ajax && ajax.readystate != 4){
ajax.abort();
ajax = null;
}
});
看起来这很有效 全球
var ajax;
var ajax;
AJAX
function swapContent() {
ajax = $.ajax({
type: 'GET',
data: params,
url: 'content.php',
success: function(data) {
$('#browser').html(data);
},
error:function(e){
// Error
}
});
}
function swapContent() {
ajax = $.ajax({
type: 'GET',
data: params,
url: 'content.php',
// -- VERIFY AJAX IS NULL -- //
beforeSend : function() {
if(ajax != null) {
ajax.abort(); // ABORT IF NOT NULL
}
},
success: function(data) {
$('#browser').html(data);
ajax = null; // NULL AJAX ON SUCCESS
},
error:function(e){
// Error
}
});
}
onPopstate
$(window).on('popstate', function() {
// Abort active requests
if(ajax && ajax.readystate != 4){
ajax.abort();
}
});
$(window).on('popstate', function() {
if(ajax && ajax.readystate != 4){
ajax.abort();
ajax = null; // NULL AFTER ABORT
}
});
我无法重现这个问题。在第一个终止后。