Home  >  Article  >  Web Front-end  >  Ajax does not execute the success callback but executes the error callback_Basic knowledge

Ajax does not execute the success callback but executes the error callback_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:47:001294browse

The attached code is as follows:
JScript code:

Copy code The code is as follows:

$.ajax({
type: "post",
url: "jsp/loginManager.jsp",
data: "name=" $('#rname').attr('value ') "&pwd=" $('#pwd').attr('value'),
dataType: "text",
success: function(data) {
alert(data);
}
});

Click to log in, successfully connected to the database and queried the value (the queried value was printed using System.out.print() on the loginManager.jsp page). But the things in success are not executed. After using breakpoints, after executing dataType, success jumps out directly, and the alert() inside is not executed. Why is this?
Changed the code as follows:
JScript code:
Copy the code The code is as follows:

$.ajax({
type: "post",
url: "jsp/loginManager.jsp",
async: true,
data: "name=" $(' #rname').attr('value') "&pwd=" $('#pwd').attr('value'),
dataType: "text",
success: function(data) {
alert(data);
},
error: function(e) {
alert(e);
}
});

But Still the same, no response, just refreshed the login page! ! !
As for the above problem of just refreshing the login page, there is a small problem in the a link. It turns out that there is href in the a link. At the beginning, href="", so I refreshed the page and entered the action before refreshing the page. So the submission data was also obtained, but it was refreshed before it could be returned. Change it to href="#" and it will be ok! Just like: