我想做的是捕捉所有错误并自己处理。
但是当 jQuery.ajax() 发生错误时,我可以知道错误选项是否出错。但是我的 window.onerror 事件无法捕捉到它。
window.onerror = function(e) {
console.log("i was here! ERROR: ", e);
console.log("-----------");
return true; //dont show errors on console
}
$(function() {
$.ajax({
url: "asdasdasd/as/da/sdtest/asdasd",
error: function() {
// ok i know here is an error and it catches on my window.onerror. BUT look at your console, still have a GET error. That error I want to handle. Can be with try/catch or inside the window.onerror. I want that Exception object. Not this one that I created.
throw new Error("it catches, but still have errors on my console");
}
});
test[0].test = "it fails";
});
你可以在这里测试:http: //jsfiddle.net/uHPXm/4/