在项目开发中,有时提交form表单时不能单单用action或者jquery的
</pre><pre style="list-style: none; padding: 0px; outline: 0px; border: currentColor; color: rgb(51, 51, 51); line-height: 1.4285; overflow: auto; font-family: Menlo,Monaco,Consolas,"Courier New",monospace; font-size: 13px; margin-top: 0px; margin-bottom: 0px; word-break: break-all; word-wrap: break-word; background-color: rgb(245, 245, 245);" class=" JScript" name="code">
表单提交方法有三种,主要说下第三种
第一种:用form自带属性<span style="color: rgb(255, 0, 0);"><strong>action</strong></span>提交
第二种:用jquery提交:<span style="line-height: 1.4285; background-color: rgb(240, 240, 240);"><strong><span style="color: rgb(255, 0, 0);">$("#formid").submit();</span></strong></span>
<span style="line-height: 1.4285; background-color: rgb(240, 240, 240);">第三种:用ajax提交:</span>
<span style="line-height: 1.4285; background-color: rgb(240, 240, 240);">但如果form表单中数据很多时,不可能一一列出,只需要用</span><pre style="list-style: none; padding: 0px; outline: 0px; border: currentcolor; line-height: 1.4285; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; margin-top: 0px; margin-bottom: 0px; word-break: break-all; word-wrap: break-word; background-color: rgb(245, 245, 245);" class=" JScript" name="code"><span style="color: rgb(255, 0, 0);"><strong>$('#yourformid').serialize()</strong></span>就可以了
</pre>
举例如下:
$.ajax({ cache: true, type: "POST", url:ajaxCallUrl, <span style="color: rgb(255, 0, 0);"><strong>data:$('#yourformid').serialize(),</strong></span>// 你的formid async: false, error: function(request) { alert("Connection error"); }, success: function(data) { $("#commonLayout_appcreshi").parent().html(data);\ } });