The development of the SSM integration project has reached a stage, and I want to slowly introduce technologies such as the front-end framework.
Suddenly encountered a puzzled question for a long time:
Ajax replaces the original form form post submit login:
404 errors all the time, heartbroken. . . .
Finally, it turns out that when ajax binds the button click event, it will trigger the post method of the form form, thus changing the url address to cancel the XHR request. . . Assy. . .
Remember to remove this form tag! ! !
Key AJAX code:
$("#login").click(function(){
var allData = {'name':$("#userName").val() , 'password':$("#password").val()}
$.ajax({
type:"post",
url:"${pageContext.request.contextPath}/loginCheck",
contentType:"application/json;charset=utf-8",
dataType:"json",
data:JSON.stringify(allData),
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
alert(errorThrown)
},
success:function(data){
alert(data['result']);
var response=data['result'];
if(response==="false"){
window.location.href="/login";
}
else {window.location.href="/items/queryItems";}
}
})
});