JQuery的捕捉任何Ajax错误 [英] JQuery catch any ajax error

查看:125
本文介绍了JQuery的捕捉任何Ajax错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕捉任何AJAX 401未经许可例外,但确实没有像改变我所有的Ajax查询。有没有办法改变它的任何$就如呼叫(覆盖任何错误处理程序)?

i like to catch any ajax 401 Unauthorised exception, but do no like to change all my ajax queries. Is there a way to change it for any $.ajax call like (overwrite any error handler) ?

推荐答案

您可以使用全局AJAX事件处理程序 .ajaxError()

you can use the global ajax event handlers .ajaxError()

$( document ).ajaxError(function( event, jqxhr, settings, exception ) {
    if ( jqxhr.status== 401 ) {
        $( "div.log" ).text( "Triggered ajaxError handler." );
    }
});

这篇关于JQuery的捕捉任何Ajax错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆