Dimitri89 Posted February 2, 2009 Share Posted February 2, 2009 Greetings all. I am experiencing a strange problem. I have a php file named sql_returnwork.php, which returns either data in XML or Table format. Now the strange issue is, for some reason when I return the XML data javascript does not seem to read it properly. I know its not the XML formatting, since if I save it AS an XML file, then it will read it perfectly as expected. Here is how it is in a nutshell if(isset($_GET['xml'])) { header('Content-Type: text/xml'); $arr = sql_returnwork(); echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; echo '<items>'; foreach($arr as $key => $value) { echo "<$key>$value</$key>"; } echo '</items>'; } else { ... bla bla bla ... } My javascript is very simple and looks like var x = xmlHttp.responseXml.getElementsByTagName("item"); alert(x.length) //This returns 0 for some reason, though when reading from the actual XML file it returns 3? Since it has 3 elements. Here is my XML file once genereated from PHP. <?xml version="1.0" encoding="ISO-8859-1"?> <items> <item> <val0>Test</val0> <val1>Test2</val1> <val2>2009-20-1</val2> </item> <item> <val0>Test</val0> <val1>Test2</val1> <val2>2009-20-1</val2> </item> <item> <val0>Test</val0> <val1>Test2</val1> <val2>2009-20-1</val2> </item> </items> I do no understand the problem. When reading from an XML file normally, it works perfect - but from a PHP file it...fails. I am running Wamp server using Apache 2.2.8 and PHP 5.2.6 Anything I am missing? Quote Link to comment Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 2, 2009 Share Posted February 2, 2009 you might want to add this into the very top of your php script <?php // begin code header ("Content-Type: text/xml"); // end code ?> Hope it helps. Regards, LPM Quote Link to comment Share on other sites More sharing options...
Dimitri89 Posted February 2, 2009 Author Share Posted February 2, 2009 Thanks man but its already there. haha Quote Link to comment Share on other sites More sharing options...
Dimitri89 Posted February 2, 2009 Author Share Posted February 2, 2009 Sorry for the double post/bump up. But I really need help solving this ASAP. Quote Link to comment Share on other sites More sharing options...
Dimitri89 Posted February 3, 2009 Author Share Posted February 3, 2009 Triple post lol. I solved it. Change header('Content-Type: text/xml'); to header('Content-Type: application/xml'); 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.