Ajax request works with .xml files but not .php files

Ajax request works with .xml files but not .php files

In my quest to implement ajax for the first time i've hit a brick wall. i've been searching for hours for a solution but with no success.   Here  is the problem.

this code works and shows an the alert

  1. function SaveReport(){
  2. $j.ajax({
  3.     type: "POST",
  4.     url: "newXMLDocument.xml",
  5.     dataType: "xml",
  6.     success: function(xml)
  7.             {
  8.                 if ($j("status",xml).text() == '1')
  9.                     {
  10.                 alert('status=1');
  11.                     }
  12.             }
  13. });

Here is the XML document-

  1. <?xml version="1.0" encoding="ISO-8859-9"?>
  2. <response>
  3.  <status>1</status>
  4.  <time>1170323512</time>
  5.  <message>
  6.    <author>John Citizen</author>
  7.    <text>Hello world!</text>
  8.  </message>
  9.  <message>
  10.    <author>John Citizen</author>
  11.    <text>Hello world again!</text>
  12.  </message>
  13. </response>
This code failed, notice the difference is that i'm calling a php file instead of an xml file
  1. function SaveReport(){
  2. $j.ajax({
  3.     type: "POST",
  4.     url: "savereport.php",
  5.     dataType: "xml",
  6.     success: function(xml)
  7.             {
  8.                 if ($j("status",xml).text() == '1')
  9.                     {
  10.                 alert('status=1');
  11.                     }
  12.             }
  13. });
Here is the PHP code


  1. <?php
  2. //echo xml
  3. header("Content-type: text/xml");

  4. echo "
  5. <?xml version=\"1.0\" encoding=\"ISO-8859-9\"?>
  6. <response>
  7.  <status>1</status>
  8.  <time>1170323512</time>
  9.  <message>
  10.    <author>John Citizen</author>
  11.    <text>Hello world!</text>
  12.  </message>
  13.  <message>
  14.    <author>John Citizen</author>
  15.    <text>Hello world again!</text>
  16.  </message>
  17. </response>"
  18. ?>

why is it not working? my PHP code is outputting the contents of the xml document.  Thanks