Reputation: 1821
I have a jquery ajax call to a c# asmx web method, which does some processing,and internally calls more api's \ DB operation ,etc etc taking approx 20-30 seconds
WEB METHOD
[WebMethod]
public void dummy()
{
File.Create(@"C:\test\test" + DateTime.Now.Millisecond.ToString() + ".txt");
System.Threading.Thread.Sleep(60000);
}
AJAX CALL
$.ajax(
{
url:Service.asmx/dummy",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
success: function (strData) {
alert('done');
}
});
The ajax call is within a loop which is fired 2 times, but the web method gets called only Once, so i tried async: false
, then web method gets hit twice but after the 60 seconds delay.
What am i doing wrong ?
Upvotes: 1
Views: 1694
Reputation: 148150
Remove the delay by System.Threading.Thread.Sleep(60000)
in code behind and send the second ajax
call after receiving the response from the server side.
$.ajax(
{
url:Service.asmx/dummy",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
success: function (strData) {
alert('done');
//send second call here
}
error: function (jqXHR, textStatus, errorThrown) {
//send second call here if required.
}
});
If you do not have any synchronization problem for simultaneous call then you can remove delay and send multiple call simultaneouly.
Upvotes: 1