ajax提交整个form表单

在项目开发中,有时提交form表单时不能单单用action或者jquery的

</pre><pre class=" JScript" name="code" style="white-space: pre-wrap; word-wrap: break-word; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 1.42857; word-break: break-all; color: rgb(51, 51, 51); border: none; list-style: none; outline: none 0px; background-color: rgb(245, 245, 245);">
表单提交方法有三种,主要说下第三种
    第一种:用form自带属性<span style="color: rgb(255, 0, 0);"><strong>action</strong></span>提交
    第二种:用jquery提交:<span style="line-height: 1.42857; background-color: rgb(240, 240, 240);"><strong><span style="color: rgb(255, 0, 0);">$("#formid").submit();</span></strong></span>
<span style="line-height: 1.42857; background-color: rgb(240, 240, 240);">    第三种:用ajax提交:</span>
<span style="line-height: 1.42857; background-color: rgb(240, 240, 240);">但如果form表单中数据很多时,不可能一一列出,只需要用</span><pre class=" JScript" name="code" style="white-space: pre-wrap; word-wrap: break-word; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 1.42857; word-break: break-all; border: none; list-style: none; outline: none 0px; background-color: rgb(245, 245, 245);"><span style="color: rgb(255, 0, 0);"><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: rgb(255, 0, 0);"><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>}
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值