Simple AJAX with xml

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2006
Posts: 11
Reputation: AndrewSmith is an unknown quantity at this point 
Solved Threads: 0
AndrewSmith AndrewSmith is offline Offline
Newbie Poster

Simple AJAX with xml

 
0
  #1
Aug 25th, 2006
hey. I'm trying to get a grasp on XML for use with AJAX.
here is my code. what i want to do is grab the stuff between the 'content' tags, and display it. then i want to take the stuff between the 'script' tags, and eval it (so it will execute).

here is my simple xml document:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <document>
  3. <myScript> alert("hello world"); </myScript>
  4. <content> This text should be displayed as content. </content>
  5. </document>

and my handleResponse code from the calling page:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function handleResponse(http_request, divID){
  2. var myDiv = document.getElementById(divID);
  3. if (http_request.readyState == 4) {
  4. if (http_request.status == 200) {
  5. myXMLDoc = http_request.responseXML;
  6. content = myXMLDoc.getElementsByTagName("content");
  7. myDiv.innerHTML = content;
  8. } else {
  9. alert("There was a problem with the request.");
  10. }
  11. }
  12. }

When i run this, i get the error "object doesn't support this property or method" ... and its complaining about the line :
content = myXMLDoc.getElementsByTagName("content");

Can anybody see what I'm doing wrong, and possibly suggest how to fix it? I'm just getting into XML, and it would be a big help
Thanks!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 75
Reputation: Sailor_Jerry is an unknown quantity at this point 
Solved Threads: 2
Sailor_Jerry's Avatar
Sailor_Jerry Sailor_Jerry is offline Offline
Junior Poster in Training

Re: Simple AJAX with xml

 
0
  #2
Aug 27th, 2006
Your getting that error because that property does not exist on the XML document.

You must first parse the document before you can access the DOM. Once you do this your code should work.

Here is some info on parsing an XML document: http://www.w3schools.com/dom/dom_parser.asp
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC