如果让Ajax和form相干扰,就要改变表单提交按钮格式为 buttom,绑定触发按钮
Ajax
<script> $(function () { $("#btnSubmit").click(function () { var url="/zhal1_project/registerUserServlet"; var data=$("#registerForm").serialize(); if (validForm()){ $.post(url,data,function (res,sta) { if (res.code=="SUCCESS"){ location.href="/zhal1_project/register_ok.html"; return; } $("#errorMsg").html(res.codeDesc); }); } }); }); </script>
form表单
<body> <form id="registerForm"> ....... <input id="btnSubmit" type="button" class="submit" value="注册"> </form> </body>
原文:https://www.cnblogs.com/jiangzishun/p/12740656.html