<script type="text/javascript"> $(function() { $('#form1').submit(function() { //当提交表单时,会发生 submit 事件。 //此处可做表单验证 //... ... var postData = $("#form1").serialize();//序列化表单,后台可正常通过post方法获取数据 $.ajax({ type: "POST", url: "/member/member/post_member", data: postData, success: function(msg) { if (msg == 0) { alert('操作成功'); window.location.href = '/member/member'; } else { alert(msg); } } }); }); }); </script> <div> <form id="form1" onsubmit="return false;"> <!--表单内容部分--> <input type="reset" value="重置" /> <input type="submit" value="提交" /> </form> </div>
jquery通过submit()和serialize()提交表单
时间: 2024-10-12 12:29:47