0
我在一个复杂的应用程序结构中工作,并且试图在处理错误方面做得更好。在代码中有一个定义的通用错误处理程序,它显示错误。Backbone Collection Fetch - 使用自定义错误处理程序覆盖ajax错误处理程序
我想我的集合/模型提取失败一点礼貌,并显示一个不错的错误信息。发生了什么事情是两人都被解雇了,但我希望将错误标记为不知何故处理,以免它继续冒泡。
// generic error handler
console.log("generic error");
$(document).on('ajaxError', function(event, xhr, settings) {
console.log("adding generic", xhr);
$("#errorDiv").append("<div>Generic error: " + xhr.status + " " + xhr.statusText + "</div>");
});
console.log("define collection");
var TestCollection = Backbone.Collection.extend({
url : "http://jsfiddle.net/Kieveli/wouoxsab"
});
console.log("fetch collection");
// fetch and provide default error
var tests = new TestCollection();
tests.fetch({
error: function(collection, response, options) {
console.log("adding custom", response);
$("#errorDiv").append("<div>Custom Error: " + response.status + "</div>");
// How to stop generic ajaxError from firing??
console.log("options", options);
}
});
你对如何阻止发生的一般错误事件的任何想法?