| | |
Simple AJAX with xml
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 11
Reputation:
Solved Threads: 0
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:
and my handleResponse code from the calling page:
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!
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)
<?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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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!
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
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
![]() |
Similar Threads
- Java Stock Trend Analysis Program :) (Java)
- this pointer (JavaScript / DHTML / AJAX)
- simple ajax script problem (JavaScript / DHTML / AJAX)
- Coding a PvP Arena - Help (PHP)
- LAMP + ActionScript Developer in OC (Web Development Job Offers)
- converting exe into xml (XML, XSLT and XPATH)
- aadhunik.com is here to help beginners (Community Introductions)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Date Validation in HTML
- Next Thread: Delay loading advertisements
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box bug calendar cart checkbox class codes column createrange() css cursor date debugger decimal design dom download dropdown element embed enter error explorer firefox focus form frameworks getselection google gwt hiddenvalue hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 object onmouseover paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select shopping size software sql text textarea toggle unicode w3c website window windowofwords windowsxp wysiwyg





