Ajax: 'parseerror' with XML being retrieved via php
If I open the php file directly, i get a properly formatted xml output, but when I use jquery's ajax method, it fails to parse the response.
Here's the php file:
-
<?php
include ("dbconn.php");
$query = "SELECT name FROM mb_cities";
$result = mysql_query($query);
echo "<response>";
while($row = mysql_fetch_array($result))
{
echo "<city>$row[name]</city>";
}
echo "</response>";
?>
Here's the ajax script:
-
$(document).ready(function() {
response = $.ajax({
type: "POST",
url: "/php/getinitdata.php",
dataType: "xml",
cache: "false",
error: function(request, error){
console.log("Error: " + error);
},
success: function(result) {
console.log("Response: " + response.responseText);
}
});
});
Output:
-
Error: parsererror
Where's the screwup?