是否有可能阻止骨干"读"要求 [英] Is it possible to stop Backbone "read" requests
问题描述
我有了的若干意见骨干的应用程序。视图之间切换触发Ajax请求来获得不同的集合。我想停止当前读Ajax请求,如果一个新的开始。这可能吗?
I have a backbone application that has a number of views. Switching between views triggers Ajax requests to get different collections. I would like to stop the current "read" ajax request if a new one is started. Is it possible?
推荐答案
好了,所以这里是我做过什么
Ok so here is what I did
我保存的获取请求在一个变量
I am saving the the fetch requests in a variable
app.fetchXhr = this.model.fetch();
在我的路由器,我有一个函数,它关闭的意见和渲染视图的照顾。它也需要触发需要为每个视图改变任何触发器的照顾,而且,是不是在这个问题相关。
In my router, I have a function that takes care of closing the views and rendering views. It also takes care of triggering any triggers needed for each view change but that is not relevant in this question.
做任何事情之前,该路由器功能执行以下
Before doing anything, this router function executes the following
//Stop pending fetch
if(app.fetchXhr.readyState > 0 && app.fetchXhr.readyState < 4){
app.fetchXhr.abort();
}
我希望这有助于
这篇关于是否有可能阻止骨干&QUOT;读&QUOT;要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!