monkotronic Posted February 7, 2007 Share Posted February 7, 2007 i'm doing an XMLHttpRequest. it fetches just fine. when i dump the responseText into my innerhtml, it is fine. that was just for testing. i wanted to assign my responseXML to a variable called areaXML. my code: ----------------------------------------------------------------------- function handleStateChange() { if(theXML.readyState ==4) { if(theXML.status == 200) { areaXML = theXML.responseXML; } } } ------------------------------------------------------------------------- but when i: theDates =areaXML.getElementsByTagName("date"); i get: Error: areaXML has no properties Source File: http://voodoo/sfv/javascript/pajax.js Line: 63 i cant figure out why! the file exists, it reads it. if i dump the responseText instead of responseXML it is ok. if i dump the responseXML, it tells me it is an XMLDocument object so that seems ok. areaXML is declared in the global space so that should be ok. what could i be missing? ??? Quote Link to comment Share on other sites More sharing options...
artacus Posted February 7, 2007 Share Posted February 7, 2007 No. getElementsByTagName is for stuff like IMG, TD, TABLE, etc. You probably want getElementById Quote Link to comment Share on other sites More sharing options...
monkotronic Posted February 7, 2007 Author Share Posted February 7, 2007 thanks for the idea, but that is one of the functions for traversing an xml tree. i have it working on another site, which is why this scenario is driving me up the wall! Quote Link to comment Share on other sites More sharing options...
artacus Posted February 8, 2007 Share Posted February 8, 2007 Is it a problem w/ variable scope then? Quote Link to comment Share on other sites More sharing options...
monkotronic Posted February 8, 2007 Author Share Posted February 8, 2007 i dont think so since areaXML is declared at the top of the script in the global space, not inside any function. it seems it must be along those lines, though, cause everything is checking out for filling the variable. is there a special way of declaring a global that i'm missing? ??? Quote Link to comment Share on other sites More sharing options...
artacus Posted February 8, 2007 Share Posted February 8, 2007 are you using something like var areaXML = ''; ? If you're pretty sure its a scope issue, you could also attach it to the document with something like this: document.areaXML = ''; function handleStateChange() ... document.areaXML = theXML.responseXML; Quote Link to comment Share on other sites More sharing options...
monkotronic Posted February 8, 2007 Author Share Posted February 8, 2007 here is more detail (the error, the html file, the xml file)... opera throws this error (more detail than firefox): Event thread: load Error: name: TypeError message: Statement on line 32: Could not convert undefined or null to object Backtrace: Line 32 of inline#1 script in http://voodoo/sfv/testxml.html var Listing = areaXML.getElementsByTagName("time"); Line 1 of script testrun(); ______________________________________________________________ here is the html file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>asdf</title> <script > var theXML; var areaXML; function createXMLHttpRequest() { if (window.ActiveXObject) { theXML = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { theXML = new XMLHttpRequest(); } } function startRequest() { var dataFile='content/monthlycalendar.xml'; createXMLHttpRequest(); theXML.onreadystatechange = handleStateChange; theXML.open("GET", dataFile, true); theXML.send(null); } function handleStateChange() { if(theXML.readyState ==4) { if(theXML.status == 200) { areaXML = theXML.responseXML; } } } function testrun() { startRequest(); var Listing = areaXML.getElementsByTagName("time"); document.getElementById("bigone").innerHTML = Listing[0].childNodes[0].nodeValue; } </script> </head> <body onload="testrun();"> <DIV align="center" id="bigone">nothinhere</DIV> </body> </html> --------------------------------------------------------------------------------------------------------------- here is the xml file being called: <?xml version="1.0"?> <!DOCTYPE area [ <!ELEMENT area (subarea)> <!ATTLIST area name CDATA " "> <!ELEMENT subarea (event)> <!ATTLIST subarea name CDATA " "> <!ATTLIST subarea title CDATA " "> <!ELEMENT event (date, time, type, topic, notes, location)> <!ELEMENT date (#PCDATA)> <!ELEMENT time (#PCDATA)> <!ELEMENT type (#PCDATA)> <!ELEMENT topic (#PCDATA)> <!ELEMENT notes (#PCDATA)> <!ELEMENT location (#PCDATA)> ]> <area name="monthlycalendar"> <subarea name="events" title="On the Schedule"> <event> <date>2007,2,7</date> <time>8PM</time> <type>lecture</type> <topic>The Call of the Wild</topic> <notes></notes> <location>Old Temple</location> </event> <event> <date>2007,2,14</date> <time>8PM</time> <type>lecture</type> <topic>Mom is On The Phone</topic> <notes></notes> <location>New Temple</location> </event> </subarea> </area> Quote Link to comment Share on other sites More sharing options...
monkotronic Posted February 9, 2007 Author Share Posted February 9, 2007 is there a way to actually see what is being stored into theXML.responseXML? if i use responseText instead, i get a dump of my file minus the markup. if i dump responseXML, i just get [object:xml document]. but when i try to access this object, that is when the error above gets thrown. what would cause a text return but no xml return? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.