开发者

Loading text while waiting for a Ajax call

开发者 https://www.devze.com 2023-02-22 18:43 出处:网络
I\'m new to Javascript/Jquery/Ajax and don\'t know how to get some text to display \'Loading...\' while waiting for an ajax call.

I'm new to Javascript/Jquery/Ajax and don't know how to get some text to display 'Loading...' while waiting for an ajax call.

So fa开发者_StackOverflow社区r I have this code which works fin

$.get("sum.php", { userid: "<?php echo $userID; ?>"},
           function(data){


                eval(data);

});

I want 'Loading...' to appear in a div called Loading until the data is returned from the Ajax call.

Thanks in advance


If your loading div has ID "loading", you could do something like this...

<div id="loading"><img src="spinner.gif" /> Loading...</div>

JavaScript using jQuery ajaxStart and ajaxStop:

$("#loading").ajaxStart(function(){
   $(this).show();
})
.ajaxStop(function(){
   $(this).hide();
});
0

精彩评论

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