Home > Web Front-end > JS Tutorial > The answer to error returning error and always returning error in JQuery ajax

The answer to error returning error and always returning error in JQuery ajax

巴扎黑
Release: 2017-07-03 10:45:40
Original
2140 people have browsed it

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);
},
});
Copy after login

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

action and execute the method successfully. But the error method keeps returning. I struggled for a long time. I also checked a lot of information. Basically it’s all kinds of attempts. I just want to switch to Ext. .

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; 
  }
Copy after login

Change it to:


public String findNetBut(){ 
    bdiList=googleFlexDAO.getBuildingIpsById(araid.trim()); 
    return SUCCESS; 
  }
Copy after login

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!

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template