除了在每个回调中添加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 );
}
} );
Run Code Online (Sandbox Code Playgroud)