Jump to content

[SOLVED] ResponseXML + PHP


Dimitri89

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/143444-solved-responsexml-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.