如何仅针对特定请求显示ajax加载gif?

发布于 2024-08-30 06:23:32 字数 330 浏览 2 评论 0原文

如何仅针对特定请求显示ajax gif? 例如,我的页面每 30 秒在后台调用一次 Web 服务,并且我不想在此回调期间显示 gif。另一方面,当我发出手动 ajax 请求时,我想显示 gif。

我正在使用 jQuery。

编辑:我没有设置全局处理程序,如下所示 http://api.jquery.com /ajaxStart/,只需附加到 .ajaxStart 事件即可。但我也不想在每次请求时手动显示/隐藏 gif。我需要一些通用的解决方案。

How do you show ajax gif only for a specific request?
For example my page is calling a web-service every 30 seconds in a background, and I don't want to show the gif during this callback. On the other hand I want to show the gif, when I'am making manual ajax requests.

I am using jQuery.

edit: I didn't setup the global handler as shown here http://api.jquery.com/ajaxStart/, just by attaching to the .ajaxStart event. But I don't want to show/hide the gif manually on every request too. I need some generic solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晌融 2024-09-06 06:23:32
$('#manualRefresh').click(function(){
    $('#myContainer').html('<img src="my-ajax-gif.gif">');
    $.get( ..., function(data){ ('#myContainer').html(data) });
});

就这样吗?

$('#manualRefresh').click(function(){
    $('#myContainer').html('<img src="my-ajax-gif.gif">');
    $.get( ..., function(data){ ('#myContainer').html(data) });
});

Like that?

北陌 2024-09-06 06:23:32

请尝试这个:

$('#save').click(function(){
    $('#ShowLoading').show();
    $.ajax( ..., success:function(data){....$('#ShowLoading').hide();}, 
          error:function(){....$('#ShowLoading').hide();});
});

HTH

Please try this:

$('#save').click(function(){
    $('#ShowLoading').show();
    $.ajax( ..., success:function(data){....$('#ShowLoading').hide();}, 
          error:function(){....$('#ShowLoading').hide();});
});

HTH

心奴独伤 2024-09-06 06:23:32

我使用 BlockUI 插件,确实非常简单。这是我为一些演示代码编写的一个简单的包装函数:

function wjBlockUI(msg) {

var defaultMsg = '<img src="../images/activity.gif" />';

if (null !== msg) {
    defaultMsg = msg
}

$.blockUI({ overlayCSS: { backgroundColor: '#aaa' }, message: defaultMsg });

}

I use the BlockUI plugin, makes it pretty easy really. This is a simple wrapper function I wrote for some demo code:

function wjBlockUI(msg) {

var defaultMsg = '<img src="../images/activity.gif" />';

if (null !== msg) {
    defaultMsg = msg
}

$.blockUI({ overlayCSS: { backgroundColor: '#aaa' }, message: defaultMsg });

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文