开发者

Show Loading Gif Before Results Appear

开发者 https://www.devze.com 2023-03-17 17:42 出处:网络
I have a query that is quite long and takes a few seconds to display the results.It is an ajax call to an external script.How can I display a loading message inside of the div, but have the loading me

I have a query that is quite long and takes a few seconds to display the results. It is an ajax call to an external script. How can I display a loading message inside of the div, but have the loading message disappear once the results are displayed?

Her开发者_C百科e is the function: >

function findstore(){
    var txt = 'Please enter the zip code to find the closest store&nbsp;<input type="text" name="zipcode" id="zipcode">';

    $.prompt(txt,{ 
        buttons:{Confirm:true, Cancel:false},
        submit: function(v,m,f){
            var flag = true;
            if (v) { }
            return flag;
        },
        callback: function(v,m,f){

            if(v){      
            var zipcode = f.zipcode;
                $.post('findstore.php',{zip:zipcode},
                       function(data){
                       $("div#demo").html(data);
                       }
                );
            }
        }
    });
}

>


In your logic you can load the animated gif inside the just before calling your callback method. You can associate the button cick with the code needed to load the gif into the div.

Then as soon as you get data back (inside function(data){}) you can remove the gif by replacing the content of the with the returned data.

0

精彩评论

暂无评论...
验证码 换一张
取 消