<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>
<html> <head> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("form").submit(function(e) { //e.preventDefault(); //阻止表单提交 alert("Submit prevented"); }); }); </script> </head> <body> <form name="input" action="./b.php" method="get"> First name: <input type="text" name="FirstName" value="Mickey" size="20"><br /> Last name: <input type="text" name="LastName" value="Mouse" size="20"><br /> <input type="submit" value="Submit"> </form> </body> </html>