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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.