I am novice in jQuery and experiencing a problem. In the simple code snippet below I am making ajax call to return current date time.If I click the button as soon as the page loads, I get the message "Button Clicked". The WebMethod also gets called. However
I do not get the message "success" which seems to me like the callback function on success is not getting called.But things work fine when I wait for a few seconds after the page loads and then click the button. Does this mean that jQuery script is taking
time to load? If that's the case, how did I get the message "Button Clicked" when I clicked the button soon after the page loaded.
likely the web service also needs a bit of time to warm up after it's being called the first time. To see that simply open a browser and put the url of the webservice in it and load it. If it's loaded and warm then open your page and click the button.
Grz, Kris.
Read my blog | Twitter Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Thanks for replying, Kris. I am not using any webservice. Its just a Page method and call is being returned immediately. Then why is that the callback function not getting called in the first few seconds. Puzzling...
KKashyap
Member
1 Points
7 Posts
jQuery ajax callback function does not fire as soon as the page loads
Dec 30, 2012 05:13 AM|LINK
I am novice in jQuery and experiencing a problem. In the simple code snippet below I am making ajax call to return current date time.If I click the button as soon as the page loads, I get the message "Button Clicked". The WebMethod also gets called. However I do not get the message "success" which seems to me like the callback function on success is not getting called.But things work fine when I wait for a few seconds after the page loads and then click the button. Does this mean that jQuery script is taking time to load? If that's the case, how did I get the message "Button Clicked" when I clicked the button soon after the page loaded.
<script> $(document).ready(function () { $("#btnClick").click(function () { GetDate(); }); }); function GetDate() { alert("Button clicked!"); $.ajax({ type: "POST", url: "WebForm1.aspx/GetDate", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert("success"); }, error: function (msg) { alert("error"); } }); } </script> <form runat="server"> <asp:Button ID="btnClick" runat="server" /> </form> //WebForm.aspx.cs [System.Web.Services.WebMethod] public static string GetDate() { return DateTime.Now.ToString(); }XIII
All-Star
182707 Points
23464 Posts
ASPInsiders
Moderator
MVP
Re: jQuery ajax callback function does not fire as soon as the page loads
Dec 30, 2012 08:03 AM|LINK
Hi,
likely the web service also needs a bit of time to warm up after it's being called the first time. To see that simply open a browser and put the url of the webservice in it and load it. If it's loaded and warm then open your page and click the button.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
KKashyap
Member
1 Points
7 Posts
Re: jQuery ajax callback function does not fire as soon as the page loads
Dec 30, 2012 09:14 AM|LINK
Thanks for replying, Kris. I am not using any webservice. Its just a Page method and call is being returned immediately. Then why is that the callback function not getting called in the first few seconds. Puzzling...
stockcer
Member
498 Points
128 Posts
Re: jQuery ajax callback function does not fire as soon as the page loads
Dec 30, 2012 06:23 PM|LINK
ASP.NET Arvixe Liaison
James River Webs, Inc.
asteranup
All-Star
30184 Points
4906 Posts
Re: jQuery ajax callback function does not fire as soon as the page loads
Dec 31, 2012 03:07 AM|LINK
Hi,
Can you debug your page method error method and check what you are getting there?
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog