The attached code is as follows:
JScript Code:
Copy Code code 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 Login to successfully connect to the database and query the value (System.out.print () print the value of the query to the loginmanager.jsp page). But the things in the success do not execute. With the breakpoint, when the execution of the datatype, success straight out, inside the alert () does not execute, this is why?
Changed the following code, as follows:
JScript Code:
Copy Code code 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 the landing page refreshed!!!
For the above just the problem of refreshing the login page, is a link in a little problem, originally I was a link inside there are href, start, href= "", so refresh the page, refresh the page before the action, so also obtained the submission of data, but before returning, it refreshed. Change to Href= "#" is OK! As:
<a href= ' # ' onclick= ' delmenucontent (cellvalue) >
There is another reason is because I am using asynchronous submission, no such verification has been successful when the button has been executed, so the page has been refreshed, to change it to synchronous submission, the button to submit the event must wait for the completion of the AJAX verification to determine whether the submission will be able to solve the problem!
A recent look at JQuery's API documentation, when using jquery ajax, if you specify datatype as JSON, always do not perform the success callback, but execute the error callback function, extremely depressed. A later version of 1.2.6 can be executed.
Then continue to download several jquery versions, such as 1.3.2,1.4.0, that specifies that datatype cannot perform success callbacks for JSON, and that only less than 1.3 versions of the success callback can be executed.
Finally went to jquery's website to find the online API document looked down, address: http://api.jquery.com/jQuery.ajax/, found datatype the following description
"JSON": evaluates the response as JSON and returns a JavaScript object. In JQuery 1.4 The JSON data are parsed in a strict manner; Any malformed the JSON is rejected and a parse the error is thrown. (Information on proper JSON formatting.)
The original jquery1.4 version of the JSON format requirements are very strict, to meet the json.org site definition of the format to perform success callback, or there will be errors, can not resolve the returned JSON data. Said is 1.4+ above, then why does the download 1.3.2 specify datatype as JSON and cannot perform success callbacks?
No wonder does not execute, originally I returned is {success:true,id:1} This irregular string, not strict JSON format, changed to {"Success": TRUE, "id": "1"} can perform the normal success callback.
JSON format summary, detailed to the json.org view.
1) Key name: enclosed in double quotes
2) String: Surround with double quotes
3) Number, Boolean type does not need to be enclosed in double quotes