Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery "async = true" call to .net web service not working asynchronously

Tags:

jquery

c#

asp.net

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.

like image 775
Praveen Avatar asked Nov 25 '25 03:11

Praveen


1 Answers

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.

like image 57
Josh Mein Avatar answered Nov 26 '25 15:11

Josh Mein