I have a .NET webservice which I need to hit asynchronously from the jQuery and update the grid based on the result got from service. My problem here is that, the service hit is async only for the first time and the subsequent requests are sync (even after specifying async=true in the ajax call) as shown below
jQuery.ajax({
type: "POST",
url: url,
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(msg) {
var result = msg.d;
return callback(result);
},
error: $.callDotNetSM.onError
});
My .NET service method is something like below.
[WebMethod(EnableSession = true)]
public static string GetData()
{
}
So, please help me in calling the service asynchronously all the times. Any help is highly appreciated.
The page your WebMethod is being called on needs to have the following in the Page Directive:
<%@ Page Async="true" EnableSessionState="False" %>
The reason for this is that ASP.NET locks the Session every time it is accessed so that it cannot run asynchronously. Even if you do not use the Session in your WebMethod the page still thinks it uses it by default unless you tell it otherwise.
Edit:
Your problem could also be that you have EnableSession="true". You may just need to set it to false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With