禁用ajaxStart()和ajaxStop()为单个请求 [英] disable ajaxStart() and ajaxStop() for a single request

查看:377
本文介绍了禁用ajaxStart()和ajaxStop()为单个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.ajaxStart()和.ajaxStop()来显示一个模式正在取得一个Ajax请求时。 (启动和停止之间)

I am using .ajaxStart() and .ajaxStop() to show a modal while an ajax request is being made. (between start and stop)

现在我想补充一个longpoll功能一直等待通知,类似于一个在该网站的左上角。

Now I'd like to add a longpoll function that keeps waiting for notifications, similar to the one on the left upper corner of this site.

我现在的问题出在禁用此模式仅适用于longpolling要求。

My problem now lies in disabling this modal only for the longpolling request..

注册和关闭处理程序载入画面:

Registering "loading screen" on and off handlers:

$(document).ajaxStart(handleAjaxStart);
$(document).ajaxStop(handleAjaxStop);

我的longpoll功能:

My longpoll function:

$.ajax({
    timeout: 35000,
    url: longPollUrl,
    success: function(data){
        if(data.queCount) $('#numQueCount').html(data.queCount);
        if(data.queAccept) $('#numQueAccept').html(data.queAccept);
    }, 
    dataType: 'json',
    complete: longpoll
});

我想:

$().off('ajaxStart');
$().off('ajaxStop');

..并开始投票,但没有喜悦后,重新连接的处理程序。

..and reattaching the handlers after starting the polling, but no joy.

我也尝试引入一个全局变量为 handleAjaxStart(),将返回在函数的第一行,但似乎彻底杀灭载入画面。

I also tried introducing a global variable into handleAjaxStart() that would return at the first line of the function, but that seems to completely kill the loading screen.

任何想法如何能做到这一点?

Any ideas how this can be achieved?

推荐答案

我想它了。

有一个在选项的属性对象阿贾克斯()采用名为全球

There is an attribute in the options object .ajax() takes called global.

如果设置为false,则不会触发 ajaxStart 事件调用。

If set to false, it will not trigger the ajaxStart event for the call.

$.ajax({
    timeout: 35000,
    url: longPollUrl,
    success: function(data){
        if(data.queCount) $('#numQueCount').html(data.queCount);
        if(data.queAccept) $('#numQueAccept').html(data.queAccept);
    }, 
    global: false,     // this makes sure ajaxStart is not triggered
    dataType: 'json',
    complete: longpoll
});

这篇关于禁用ajaxStart()和ajaxStop()为单个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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