【发布时间】:2014-02-08 22:57:50
【问题描述】:
我有 2 个 JS 类:
第一个:
var class1 = function() {
this.obj = new class2
this.stopLongPollAjax = function() {
obj.abort = true;
obj.ajax.abort();
delete obj; // it's important part for me
}
var self = this;
}
第二个:
var class2 = function() {
this.abort = false;
this.ajax = null;
this.init = function() {
self.longpoll();
}
this.longpoll = function() {
if(!self.abort) {
self.ajax = $.ajax({
type: 'POST',
url: //url here
complete: function() {
self.longpoll();
},
success: function(response) {
if(response == 1) {
// callback
}
}
});
}
var self = this;
this.init();
}
当我从 class1 调用 stopLongpoll 方法时,longpoll 不会进行另一个循环(当它完成时),但它不会在调用 stopLongpoll 方法后立即停止。有任何想法吗?
PS:如果我的代码不容易阅读或理解,我可以解释一下。
【问题讨论】:
标签: javascript jquery ajax long-polling