1

Within a backbone app, I am making a call with fetch when a users takes a certain action:

 changeDay: function() {
  this.collection.fetch({
    success: function() {
      lr.primaryView.addAllEvents();
    }
  });
 },
 ...

Sometimes, a user takes actions that calls this changeDay method again before the first request has successfully responded. In these cases, I want to cancel the previous request. I am familiar with how to do this with vanilla jQuery (it is outlined here) but I am unable to easily use that approach here since the XHR object is hidden behind fetch. How can I solve this?

Community
  • 1
  • 1
AdamVickers
  • 119
  • 2
  • 5

1 Answers1

3

Backbone.fetch actually returns the jQuery XHR object:

 changeDay: function() {
  thisXHR = this.collection.fetch({
    success: function() {
      lr.primaryView.addAllEvents();
    }
  });
 },
 ...
Edward M Smith
  • 10,627
  • 2
  • 46
  • 50