0

I'm trying to parse XML in an Ajax response. When the server returns a 200 everything works fine. But it seems like XML parsing in JQuery is disabled on error.

statusCode:{
200:function(xml){alert($(xml).find("error").text());},
404:function(xml){alert($(xml).find("error").text());}
}

If I send a 200 I get the correct alert. But if I change the response code to whatever error I like, I just get an empty alert box. Am I plain stupid for sending text/xml on error, is this a bug in jquery or where am I going wrong?

Hope someone can help.

Thanks

1 Answer 1

1

According to jQuery documentation,

If the request is successful, the status code functions take the same parameters as the success callback which is "success(data, textStatus, jqXHR)";

if it results in an error, they take the same parameters as the error callback which is "error(jqXHR, textStatus, errorThrown)"

That means in your 404 callback "function(xml){alert($(xml).find("error").text());" the 'xml' is actually the jqXHR object and understandably $(xml).find("error").text() is nothing.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to your hint I got it solved: I had to use $(xml.responseXML).find("error") That way the response got transformed into a jQuery Object on which I could then perform the find() Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.