Home > Article > Web Front-end > The answer to error returning error and always returning error in JQuery ajax
This article is shared by the editor of Script House to share with you a summary of the answers to the error return error and error return in ajax in JQuery. Friends in need can refer to the following
Enter BaiduSearchThis question, I found someone said this
The async of Ajax in Jquery defaults to true (asynchronous request). If you want to execute another Ajax after it is executed, For an Ajax, you need to set async=false
I then processed it in ajax
async: false, and found that submitting normal data returned normal without errors.
The code is as follows
##
$.ajax({ type: "POST", async: false, url:urllink, data:data, dataType:"html", success:function(msg){ alert(data) }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); }, });One last thing to add: Sending errors may be caused by the following two, or other programs The problem requires us to take it seriously. 1. data: "{}", if the data is empty, you must pass "{}"; otherwise, the returned data will be in xml format. And prompts parsererror.
The answer to jQuery ajax always returning error is as follows:
Today I used ajax to do asynchronous deletion and encountered a problem. ajax can request I found that some methods in action start with get. If you carefully print the return of ajax, you will definitely find that when ajax returns, it will obtain all methods starting with get in the action, including of course the methods in the action. After getting it, it is different from other get methods. you know! At this time, ajax will report a 500 error. Ajax will enter the error method when the status reaches 300.The modification method is: very simple, modify the method starting with get in the action to something else, for example;
public String getNetBut(){ bdiList=googleFlexDAO.getBuildingIpsById(araid.trim()); return SUCCESS; }Change it to:
public String findNetBut(){ bdiList=googleFlexDAO.getBuildingIpsById(araid.trim()); return SUCCESS; }This is OK! This error is generally difficult to find, but you can still spot it if you are careful! Okay, the answers to the error return error and error always returned in JQuery ajax are all described. I hope you all like it.
The above is the detailed content of The answer to error returning error and always returning error in JQuery ajax. For more information, please follow other related articles on the PHP Chinese website!