0

I need to access the xhr object when I call Backbone fetch.

My understanding from the docs is that all Backbone.sync methods return a jqXHR object.

However, when I do this...

var xhr = this.collection.fetch();
console.log( xhr );

...xhr is coming up "undefined". (The fetch call works as expected, and loads data from the server.)

Any ideas as to what I am missing?

EDIT:

My bad. The collection fetch prototype was being overridden elsewhere and was not returning the jqXHR object.

user1031947
  • 6,294
  • 16
  • 55
  • 88

2 Answers2

2

Probably you have overrided Backbone.sync or fetch methods. In this case you have to return the super call. For example:

fetch : function () {
  // ...
  return Backbone.Model.prototype.fetch.apply(this, arguments);
}
ProgramFOX
  • 6,131
  • 11
  • 45
  • 51
Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55
-1

I believe you can catch the XHR object in the success callback function that you would have to pass to the fetch() function.

Morgan
  • 1