显示一个AJAX请求期间,微调? [英] Showing a spinner during an AJAX request?

查看:88
本文介绍了显示一个AJAX请求期间,微调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是显示一个微调的最好方法是什么?

what is the best way to show a spinner?

我有prepared一个div(ID =微调),这应该是加载过程中可见。

I have prepared a div(id="spinner"), that should be visible during loading.

推荐答案

你使用jQuery?

如果这样你就可以使用:

If so you can use:

ajaxStart和放大器; ajaxStop: http://docs.jquery.com/Ajax

ajaxStart & ajaxStop: http://docs.jquery.com/Ajax

例如:

$(function(){

    // hide it first
    $("#spinner").hide();

    // when an ajax request starts, show spinner
    $.ajaxStart(function(){
        $("#spinner").show();
    });

    // when an ajax request complets, hide spinner    
    $.ajaxStop(function(){
        $("#spinner").hide();
    });
});

您可以微调一点与增加和减少的情况下,你有很多同时请求的请求计数器。

You can fine tune a little with a request counter that increments and decrements in case you have a lot of simultaneous requests.

如果你不使用jQuery,检查了jQuery的来源$ C ​​$下的事件ajaxStart在普通的旧JavaScript的实际注册。

If you don't use jQuery, check out the jQuery Source code for which events ajaxStart actually register in plain old javascript.

HTH 亚历克斯

这篇关于显示一个AJAX请求期间,微调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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