Scenario: Within the onblur event of a html input control I send an async http post to a resource i.e. t.aspx.
场景:在html输入控件的onblur事件中,我将异步http post发送到资源,即t.aspx。
I do not care if it ever returns, however if the users 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.
我在使用我们的模拟器时看到的是,当我单击提交时,当我减慢t.aspx以减少10秒(page_load Thread.Sleep(10000))时,它继续等待10秒的剩余时间然后提交。
I need the form to submit straight away. Below is a snippet of the ajax code
我需要表格直接提交。下面是ajax代码的片段
var _requestData = "{ " + "\"subject\": { " + "\"param1\": \"" + $("#param1").val() + "\", " + "\"param2\": \"" + $("#param2").val() + "\" " + "}" + " }";
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 });
$ .ajaxSetup({url:“t.aspx”,type:“POST”,processData:false,contentType:“application / json”,dataType:“json”,success:sucessfulCallback,error:unsucessfulCallback});
$.ajax({ data: _requestData });
$ .ajax({data:_requestData});
I have also tried var myAjax = $.ajax ..... and calling myAjax.abort() within the form submit. No luck there either.
我也尝试了var myAjax = $ .ajax .....并在表单提交中调用myAjax.abort()。也没有运气。
Any help would be much appreciated...
任何帮助将非常感激...
Regards David
2 个解决方案
#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.
您没有提到您正在运行的Jquery版本。旧版本有一个已知错误,正如您所描述的那样:http://dev.jquery.com/ticket/2935。
#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
}
#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.
您没有提到您正在运行的Jquery版本。旧版本有一个已知错误,正如您所描述的那样:http://dev.jquery.com/ticket/2935。
#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
}