简体   繁体   English

如何在ajax调用时显示加载图像

[英]how to show loading image while ajax call

I need to show loading image while ajaz is called.... I did some work on this.... But it was not helpful ...It is not showing loading image.... And i want to block screen when image is loading... my ajax is here below... 我需要在调用ajaz时显示加载图像...。我对此做了一些工作。...但这没有帮助...它没有显示加载图像...。并且我想在图像显示时阻止屏幕正在加载...我的ajax在下面...

----ajax---

function checkEmail(value_email_mobile) {

                 // before the request, show the GIF
                 //$('#loader').show();
                if (value_email_mobile !== '') {

                     //alert('te');
                    $.ajax({
                        type: "POST",
                        url: url_check_user_avail_status, 
                        data: "value_email_mobile="+value_email_mobile,
                        success: function(msg) {

                            //alert(msg);

                            //$('#psid').html("<img src='images/spacer.gif'>");
                              $('#loader').hide();
                            $('#validation').html(msg);


                            //

                            //$('#sid').sSelect({ddMaxHeight: '300px'});

                        },
                        error: function() {
                            //alert('some error has occured...');
                        },
                        start: function() {
                            //alert('ajax has been started...');
                             $("#loader").show();
                        }
                    });
                }
            } 

------html--

<div id="loader" style="display:none;"><img src="<wait.png" ></div>

For one thing, your image tag is invalid <img src="<wait.png" > should look like <img src="wait.png"/> 一方面,您的图片标签无效<img src="<wait.png" >应该看起来像<img src="wait.png"/>

As for the loader, $.ajax has an option called beforeSend. 至于加载器,$。ajax有一个名为beforeSend的选项。 You can use it like so: 您可以这样使用它:

                $.ajax({
                    type: "POST",
                    url: url_check_user_avail_status, 
                    data: "value_email_mobile="+value_email_mobile,
                    beforeSend: function () {
                                    $("#loader").show();
                                },
                    success: function(msg) { // success code here
                         $("#loader").hide();
                     });

$.ajax doesn't have start method. $ .ajax没有start方法。 Instead you can just show the spinner before calling $.ajax and it will work fine. 相反,您可以仅在调用$.ajax之前显示微调$.ajax ,它将正常工作。

if (value_email_mobile !== '') {

    $("#loader").show();

    $.ajax({
        type: "POST",
        url: url_check_user_avail_status, 
        data: "value_email_mobile="+value_email_mobile,
        success: function(msg) {
            $("#loader").hide();
        },
        error: function() {}
    })

   // ...

write this code is working for all ajax request fire on your website. 编写此代码适用于您网站上所有的ajax请求。

$( document ).ajaxStart(function() {
    $("#loader").show();
});

Then write ajax stop code. 然后编写ajax停止代码。

$( document ).ajaxStop(function() {
    $("#loader").hide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM