User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 360,994 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,543 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 931 | Replies: 1
Reply
Join Date: Jul 2006
Posts: 11
Reputation: AndrewSmith is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
AndrewSmith AndrewSmith is offline Offline
Newbie Poster

Help Simple AJAX with xml

  #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:

<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<myScript> alert("hello world"); </myScript>
<content> This text should be displayed as content. </content>
</document>

and my handleResponse code from the calling page:
function handleResponse(http_request, divID){
   var myDiv = document.getElementById(divID);
   if (http_request.readyState == 4) {
      if (http_request.status == 200) {
          myXMLDoc = http_request.responseXML;
          content = myXMLDoc.getElementsByTagName("content");
          myDiv.innerHTML = content; 
   } else {
   alert("There was a problem with the request.");
  }
 }
}

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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Carmel, IN
Posts: 67
Reputation: Sailor_Jerry is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Sailor_Jerry's Avatar
Sailor_Jerry Sailor_Jerry is offline Offline
Junior Poster in Training

Re: Simple AJAX with xml

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:32 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC