By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

Handling an AJAX response

P: 26
Hey, I'm looking to handle an XML response depending on what's sent. Better than I can explain it, here's an example...

Expand|Select|Wrap|Line Numbers
  1. function stateChanged () {
  2.     if (xmlHttp.readyState == 4) {
  3.         var xmlDoc = xmlHttp.responseXML;
  5.         if (xmlDoc.getElementsByTagName("error")) {
  6.             alert('error');
  7.         }
  8.     }
  9. }
Alright, the response will be either all in <a></a> or <b></b> tags, but if there is an error, it will return <error></error> with all of the errors inside. I'd like to set up an if/else that will detect if the response is <error></error> or if it's actually something I'm going to use.

I don't know how to differentiate the two though. What I have there in the if/else seems to always return true. Has anyone else had this problem or knows the solution? Thanks!
Oct 10 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
Check the length of the array returned by getElementsByTagName().
Oct 15 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.