Javascript:如何停止多个jQuery ajax错误处理程序? [英] Javascript: How to stop multiple jQuery ajax error handlers?

查看:171
本文介绍了Javascript:如何停止多个jQuery ajax错误处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个团队成员把它放在我们的项目中

A team member put this into our project

$(function() {
    $("body").bind("ajaxError", function(event, XMLHttpRequest, ajaxOptions, thrownError){
        alert(thrownError);
    });
}

然而,我想抑制我的一个错误(因为这将是噪音,不需要验证)

However I want to supress one of my errors (as it would be noise and verification isn't needed)

function blah() {

    ...

    errFunc = function(event, xhr, opts, errThrown) {
        //what could I do here?
        //event.stopImmediatePropagation()?
    }

    $.ajax({
        url        : '/unimportant_background_refresh',
        type       : 'GET',
        data       : { },
        dataType   : 'json',
        success    : updateBackgroundStuff,
        error      : errFunc,  // Suppresses error message.
    });

}

如何停止捕获所有错误请问吗我可以在错误函数中执行某些操作,例如 {event.StopPropogation();或者我必须制定一些机制,让所有的选择都忽略了事情吗?

How can I stop the catch all error from happenning please? Can I just do something in the error function such as { event.StopPropogation(); } or must I work out some mechanism for having the catch all selectively ignore things please?

推荐答案

通过传递全局选项,可以禁用全局事件,对于特定的Ajax请求,如下所示:

Global events can be disabled, for a particular Ajax request, by passing in the global option, like so:

 $.ajax({
   url: "test.html",
   global: false,
   // ...
 });

取自: http://docs.jquery.com/Ajax_Events

这篇关于Javascript:如何停止多个jQuery ajax错误处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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