Ajax提交form表單總是返回error函式
阿新 • • 發佈:2019-01-31
這是ajax程式碼
function saveUser() {
$.ajax({
type:"POST",
url:"SaveUser.action",
data:$('#fm').serialize(),
dataTyep:"JSON",
async: false, //加上之後不在跳轉進error
success:function(data) {
var config = confirm("註冊成功,是否登陸" );
if(config){
window.location.href="Login.action";
}else{
window.location.reload();
}
},error:function(){
alert("系統異常");
}
});
}
這是html程式碼:
<form id="fm" method="post">
姓名:<input type="text" name="uname" required/> <br/>
電話:<input type="text" name="uphone" id="uphone" required/><span id="checkPhone" color="red"></span><br/>
郵箱:<input type="text" name="uemail" id="uemail" required/><span id="checkEmail" color="red"></span><br/>
證件號:<input type="text" name="uidcard" id="uidcard" required/><span id="checkIdCard" color="red"></span><br/>
密碼:<input type="password" name="upwd" id="pwd" required/><span id="checkPwd" color="red"></span><br/>
確認密碼:<input type="password" name="upwdagain" id="pwdagain" required/><br/>
性別:<input type="radio" name="usex" value="男" checked="checked"/>男<input type="radio" name="usex" value="女"/>女<br/>
<input type="submit" onclick="saveUser()" value="提交"><input type="reset" value="重置">
</form>
修改方法:再ajax裡邊加上了async: false, 原來是沒有加它的,然後問題解決了