2013-05-20 37 views
4

我有一个jqXHR对象,我从骨干收集得到:调用jqXHR.abort时不会触发错误?

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

有时候我然后需要调用xhr.abort()。但是这也触发了错误回调。

如何在不触发错误的情况下调用xhr.abort()?

回答

6

将始终调用错误函数。但你可以检查它是否在误差函数中止,而忽略它:

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

我,我知道这是很久以前的事,但我发现该属性是状态文本,不textStatus。 – noahpc

相关问题