Call jqXHR.abort without causing an error?

I have a jqXHR object that I get from the base set:

var xhr = this.collection.fetch({ error: function() { alert("oh noes!"); } }); 

Sometimes I need to call xhr.abort (). But it also causes an error callback.

How can I call xhr.abort () without triggering an error?

+4
source share
1 answer

The error function will always be called. But you can check if this interrupt was in the error function and ignore it:

  var xhr = this.collection.fetch({ error: function(model, jqXHR, options) { if (jqXHR.textStatus != "abort") alert("oh no!"); } }); 
+6
source

Source: https://habr.com/ru/post/1481815/


All Articles