How do I display a spinning "busy" indicator at a specific point in a web page?

I want to start/stop the indicator when an Ajax request commences/completes.

这真的只是一个显示/隐藏动画gif的问题,还是有更优雅的解决方案?

推荐答案

您可以只显示/隐藏gif,但也可以将其嵌入ajaxSetup,因此每次ajax请求都会调用gif.

$.ajaxSetup({
    beforeSend:function(){
        // show gif here, eg:
        $("#loading").show();
    },
    complete:function(){
        // hide gif here, eg:
        $("#loading").hide();
    }
});

One note is that if you want to do an specific ajax request without having the loading spinner, you can do it like this:

$.ajax({
   global: false,
   // stuff
});

That way the previous $.ajaxSetup we did will not affect the request with global: false.

详情请浏览:http://api.jquery.com/jQuery.ajaxSetup

Jquery相关问答推荐

在shiny 的datatable列中启用智能搜索

JQuery:$.get 不是函数

为什么在 jQuery 插件中返回 this.each(function())?

Jquery如何通过数组中的属性查找对象

为什么我的 toFixed() 函数不起作用?

jQuery 动画滚动

对自定义属性执行客户端验证

如何使用 jQuery 将分钟转换为小时/分钟并添加各种时间值?

如何立即启动 setInterval 循环?

禁用 Android 网页中输入焦点的zoom

Angular.js 在多个元素中重复

Codemirror 编辑器在单击之前不会加载内容

jQuery $.cookie 不是一个函数

您如何处理 jQuery 中的表单更改?

jQuery UI 中的 disableSelection 用于什么?

jQuery 不会从 AJAX 查询中解析我的 JSON

在 jQuery UI 自动完成上没有检测到结果

Jquery:如何判断元素是否具有某些 css 类/样式

PHPStorm IDE 中低效的 jQuery 使用警告

计算文本宽度