当AJAX调用过程中显示“加载”的形象 [英] Display 'loading' image when AJAX call is in progress

查看:145
本文介绍了当AJAX调用过程中显示“加载”的形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jQuery的Ajax调用:

I have the following jQuery Ajax call:

$.ajax({
                   type: "POST",
                   url: "addtobasket.php",
                   data: "sid=<?= $sid ?>&itemid=" + itemid + "&boxsize=" + boxsize + "&ext=" + extraval,
                   success: function(msg){
                     $.post("preorderbasket.php", { sid: "<?= $sid ?>", type: "pre" },
                     function(data){
                        $('.preorder').empty();
                         $('.preorder').append(data); 
                     }); 
                   }
                 });

我要显示的图像时,Ajax调用正在进行中。我该怎么办呢?

I want to display an image when the ajax call is in progress. How can I do that?

谢谢

推荐答案

试试这个:

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#loading')
            .hide()
            .ajaxStart(function() {
                $(this).show();
            })
            .ajaxStop(function() {
                $(this).hide();
            });
    });
</script>

<div id="loading">
        Loading....
</div>

这将每次你做一个Ajax请求的时候显示加载图像,我已经implented该div在我的网页上,因此它不会与页面阻挠,但你总是可以看到,当一个Ajax调用是怎么回事上。

This will show the loading image each time you are doing an ajax request, I have implented this div at the top of my pages, so it does not obstruct with the page, but you can always see when an ajax call is going on.

这篇关于当AJAX调用过程中显示“加载”的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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