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

Problem with XMLHttpRequest.responseXML

P: 3
Hi,

I'm pulling my hair for some time with this problem today. Will greatly appreciate if some one could provide me a solution.

I'm using ajax to get a list of categories to be populated in a dropdown.

My main code is below.

Expand|Select|Wrap|Line Numbers
  1. function makeRequest() {
  2.  
  3.                 if (window.ActiveXObject)
  4.                         return new ActiveXObject("Microsoft.XMLHTTP");
  5.                 else if (window.XMLHttpRequest)
  6.                         return new XMLHttpRequest();
  7.                 else {
  8.                         alert("Your browser does not support AJAX.");
  9.                 return null;
  10.                 }
  11.  
  12. }
  13.  
  14.  
  15.  
  16.  var http = makeRequest();
  17.  
  18.  function sendRequest(url, callbackfn) {
  19.          http.open('get', url);
  20.          http.onreadystatechange = callbackfn;
  21.          http.send( null );
  22.  }
  23.  
  24.  
Problem is in the next section of code.

Expand|Select|Wrap|Line Numbers
  1. var response = http.responseXML;
  2. var row = response.getElementsByTagName('topic');
  3.  
This works fine in FF, Opera, Safari, Chrome showing the dependable dropdowns, but not in IE. the row is empty when checked in ie.

when i do an alert
Expand|Select|Wrap|Line Numbers
  1. alert(row.length);
  2.  
i get zero as length. i have no clue why the length becomes zero. IE shows no error message also.

the xml returned by the php script is given below.
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <topics>
  3.   <topic id="1" title="Arithmetic"/>
  4.   <topic id="2" title="Algebra"/>
  5.   <topic id="3" title="Geometry"/>
  6.   <topic id="4" title="Word Problems"/>
  7.   <topic id="5" title="Miscellaneous"/>
  8. </topics>
  9.  
please give me some advice
Feb 22 '10 #1
Share this Question
Share on Google+
3 Replies


RamananKalirajan
100+
P: 607
Are you getting the xml when you aler the variable "response" ?

Thanks and Regards
Ramanan Kalirajan
Feb 22 '10 #2

P: 3
try {
var response = http.responseXML;
alert(response);
var row = response.getElementsByTagName('topic');
} catch(exception) {
alert('An execption occured.' + exception.message);
}
In ie i'm getting an alert window showing [object]..

Can anybody give a clue....

thanks
Feb 23 '10 #3

P: 3
Expand|Select|Wrap|Line Numbers
  1. var response = http.responseText;
  2. alert(response);
  3.  
will show me the xml file.

Expand|Select|Wrap|Line Numbers
  1. var response = http.responseXML;
  2. alert(response);
  3.  
gives [object] as o/p..

thanks..
Robert
Feb 23 '10 #4

Post your reply

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