html代码:
<a onclick="checkLogin()">
<input value="登录" style="width:100%;" type="submit">
</a>
注意看此时的 type 为 submit
Ajax代码:
$.ajax({
url: "/userLogin",
data: {
"userName": userName,
"userPwd": userPwd
},
success:function (data) {
if (data=="成功"){
alert("登录成功!")
}else if (data=="失败"){
alert("登录失败!")
}
}
})
当 html 代码中 type 为 submit 时,尝试修改type、dataType,无论怎么都没有返回也没有进入success。并且 form 表单中只能以 get 方式进行提交,当改为 post 时,点登录立马报以下错误:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method ‘POST’ not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘POST’ not supported
把 html 代码中 type 改成 button 后,它终于返回了同时也进入了success。并且当 form 表单中的提交方式为 post 时也没有再报错。