有沒有辦法處理jQuery中的AJAX回調引發的異常,除了向每個回調添加try..catch塊?在這種情況下不會調用錯誤函數。在jQuery AJAX回調中引發的異常吞噬?
$.ajax(
{
url: 'myurl.rails',
success: function(data)
{
throw 'Oh no!';
},
error: function (xhr, textStatus, errorThrown)
{
console.log('AJAX call failed', xhr, textStatus, errorThrown);
}
});
我很好奇,如果有人知道*爲什麼*它不關心是否引發異常:http://stackoverflow.com/questions/11800349/why-does-jquery-swallow-exceptions-in-ajax-success-回調 – 2012-08-03 17:19:10