Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I am working on a task where I have used WebMethod using Json to insert and retrieve data from data base,

Now I want a gif image shows in a DIV whenever a WebMethod is called.

My js code is like this:
function getvalues(j, selectedTab) {
 $("#DVloading").show();
    $.ajax({
        type: "POST",
        url: "xxx.aspx/LoadData",
        data: "{'id':'" + j + "','selectedTab':'" + selectedTab + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            if (msg.d.length > 0) {
                var dv = document.getElementById("xxxDiv");
                dv.innerHTML += msg.d;
            }
        },
        async: false,
        error: function(xhr, status, error) {
            //alert(xhr.statusText);
        }
    });
 $("#").hide();
} 

I have the page body like this:
<body>
    <form id="form1"  runat="server">
    <div>
        <div id="DVloading" style="display:none;">
          <img src="../Images/circular.gif" width="20" height="23" />
        </div>
        <div id="xxxDiv">
        </div> 
    </form>
</body></div>

But Here whenever the WebMethod is called the whole page is hanged for 10 second(the time to fetch data from DB) and nothing does. and when it loads all data then released the hanged. Image is not showing there.

Any help is greatly appreciated.

regards,

Tanweer,
Posted
Updated 19-Apr-11 21:25pm
v2
Comments
Toniyo Jackson 20-Apr-11 3:26am    
Pre tag added

I noticed your tags are not properly closed or closed on the wrong location. Try to fix them first.
 
Share this answer
 
v2
Comments
tanweer 20-Apr-11 3:39am    
Thank you very much for your reply. I don't think this is a tag closing problem here when I paste the html that was not encoded so an extra DIV was added there mistakenly.
My exact html is:
<body>
<form id="form1" runat="server">
<div>
<div id="DVloading" style="display:none;">
<img src="../Images/circular.gif" width="20" height="23" />
</div>
<div id="xxxDiv">
</div>
</div>
</form>
</body>
There are a couple of ways, to do this. One example

C#
jQuery.ajaxSetup({
  beforeSend: function() {
     $('#loader').show()
  },
  complete: function(){
     $('#loader').hide()
  },
  success: function() {}
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900