jQuery ajax发布阻止表单提交 [英] jquery ajax post blocking form submit

查看:433
本文介绍了jQuery ajax发布阻止表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案:在html输入控件的onblur事件中,我向资源(即t.aspx)发送了一个异步http帖子.

Scenario: Within the onblur event of a 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 users clicks submit I want the form to submit.

通过使用模拟器我看到的是,当我单击提交时,我将t.aspx放慢下来需要10秒钟(page_load Thread.Sleep(10000))时,它将继续等待10秒钟的剩余时间,然后提交.

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.

我需要立即提交表格.下面是ajax代码的片段

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()+"\""+"}"+"};

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

$.ajaxSetup({ 网址:"t.aspx", 输入:"POST", processData:否, contentType:"application/json", dataType:"json", 成功:sucessfulCallback, 错误:unsucessfulCallback });

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

$.ajax({ 数据:_requestData });

$.ajax({ data: _requestData });

我也尝试了var myAjax = $ .ajax .....并在表单提交中调用myAjax.abort().那里也没有运气.

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...

问候 大卫

推荐答案

在服务器端,您需要检查用户是否仍与服务器连接.通过使用以下命令.

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
}

这篇关于jQuery ajax发布阻止表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆