Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:47:00
Original
1310 people have browsed it

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:
success回调 error回调
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template