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