我正在进行搜索请求考虑一下:
用户输入活动流的“过滤器A”。 集合的URL更改为表示过滤器 调用collection.fetch 用户快速在xhr之前输入“过滤器B”,“过滤器A”返回以重置集合。 “过滤器B”从服务器返回,“过滤器B”自动调用collection.reset “过滤器A”最终返回(在“过滤器B”之后)并将集合重置为“过滤器A”。 该应用程序现在处于错误的状态。
如何中止先前的待处理请求。
self.collection = new searchCollection();
self.collection.fetch({
timeout : 60000,
type : 'POST',
data : {
"searchString" : searchKey
},
beforeSend : function(xhr) {
},
success : function(result) {
},
error : function(xhr, status, error) {
}
});
答案 0 :(得分:3)
维护变量以保存获取请求。
self.fetchXhr = self.collection.fetch();
在发出任何获取请求之前,请检查变量是否具有有效且持续的请求。
if(self.fetchXhr != undefined && self.fetchXhr.readyState > 0 && self.fetchXhr.readyState < 4)
self.fetchXhr.abort();