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
- function SaveReport(){
- $j.ajax({
- type: "POST",
- url: "newXMLDocument.xml",
- dataType: "xml",
- success: function(xml)
- {
- if ($j("status",xml).text() == '1')
- {
- alert('status=1');
- }
- }
- });
Here is the XML document-
- <?xml version="1.0" encoding="ISO-8859-9"?>
- <response>
- <status>1</status>
- <time>1170323512</time>
- <message>
- <author>John Citizen</author>
- <text>Hello world!</text>
- </message>
- <message>
- <author>John Citizen</author>
- <text>Hello world again!</text>
- </message>
- </response>
This code failed, notice the difference is that i'm calling a php file instead of an xml file
- function SaveReport(){
- $j.ajax({
- type: "POST",
- url: "savereport.php",
- dataType: "xml",
- success: function(xml)
- {
- if ($j("status",xml).text() == '1')
- {
- alert('status=1');
- }
- }
- });
Here is the PHP code
- <?php
- //echo xml
- header("Content-type: text/xml");
- echo "
- <?xml version=\"1.0\" encoding=\"ISO-8859-9\"?>
- <response>
- <status>1</status>
- <time>1170323512</time>
- <message>
- <author>John Citizen</author>
- <text>Hello world!</text>
- </message>
- <message>
- <author>John Citizen</author>
- <text>Hello world again!</text>
- </message>
- </response>"
- ?>
why is it not working? my PHP code is outputting the contents of the xml document. Thanks