调用jqXHR.abort时不会触发错误?
问题描述:
我有一个jqXHR对象,我从骨干收集得到:调用jqXHR.abort时不会触发错误?
var xhr = this.collection.fetch({
error: function() { alert("oh noes!"); }
});
有时候我然后需要调用xhr.abort()。但是这也触发了错误回调。
如何在不触发错误的情况下调用xhr.abort()?
答
将始终调用错误函数。但你可以检查它是否在误差函数中止,而忽略它:
var xhr = this.collection.fetch({
error: function(model, jqXHR, options) {
if (jqXHR.textStatus != "abort")
alert("oh no!");
}
});
我,我知道这是很久以前的事,但我发现该属性是状态文本,不textStatus。 – noahpc