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?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Backbone.js PushState routes .htaccess only workin
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
I assume you're using backbone with jQuery. If so, the following question seems to provide an answer for you:
Abort Ajax requests using jQuery
Backbone
fetch
returns thexhr
they're talking about, IIRC.Ok so here is what I did
I am saving the the fetch requests in a variable
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
I hope this helps
Yet another late reply in case someone else runs into this.
I ended up overwriting Backbone.sync to add a XHR object pool and an option to abort pending requests on fetch.