Home > Jquery > Display Loading Image Using Jquery Ajax Methods in Asp.net

Display Loading Image Using Jquery Ajax Methods in Asp.net


Often we need to display a loading indicator whenever an ajax request is done. To accomplish this you can look at the following code:

<script src=”http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>

<script language="javascript">

$(document).ready(function() {
$("# btnGetName ").click(function() {
 $.ajax({
 type: "POST",
 url: “../Default.aspx/GetName",
 data: "{}",
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: function(msg) {
 $("# divName ").html(msg.d);
 }
 });
 });
$("# loading ").ajaxStart(function() {
$(this).show();
});
$("# loading ").ajaxStop(function() {
$(this).hide();
});
});
</script>
<pre>
</pre>
<body>
<form id="form1" runat="server">

 <div id="loading" align="center" style="padding-right: 25px; z-index: 3; padding-left: 25px;
 left: 45%; top: 45%; padding-bottom: 15px; padding-top: 15px; position: absolute;">
 <img alt="Loading..." id="ImgLoader" runat="server" src="loader.gif" />
 </div>

 <div id="divName"></div><input id="btnGetName" type="button" value="Get Name" /></div>

</form>
</body>

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: