'Why my Ajax post request is blocking in form submit?

Scenario: Within the onblur event of an HTML input control I send an async HTTP post to a resource i.e. t.aspx.

I do not care if it ever returns, however, if the user clicks submit I want the form to submit.

What I am seeing from using our simulators is that when I slow down t.aspx to take 10 seconds (page_load Thread.Sleep(10000)) when I click submit it continues to wait for the remainder of the 10 seconds and then submits.

I need the form to submit straight away. Below is a snippet of the ajax code

var _requestData = "{ " + "\"subject\": { " + "\"param1\": \"" + $("#param1").val() + "\", " + "\"param2\": \"" + $("#param2").val() + "\" " + "}" + " }";

$.ajaxSetup({
    url: "t.aspx",
    type: "POST",
    processData: false,
    contentType: "application/json",
    dataType: "json",
    success: sucessfulCallback,
    error: unsucessfulCallback
});

$.ajax({
    data: _requestData
});

I have also tried var myAjax = $.ajax ..... and calling myAjax.abort() within the form submit. No luck there either.

Any help would be much appreciated...

Regards David



Solution 1:[1]

You don't mention which Jquery version you are running. Older versions had a known bug which is exactly as you describe: http://dev.jquery.com/ticket/2935.

Solution 2:[2]

At Server side, you need to check user still connect with server or not. By using the following command.

if (!Response.IsClientConnected)
{
   // process user request
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Douglas F Shearer
Solution 2 user229044