XML Parser Error
Posted by Prabhu Beeman on August 11, 2009
I was trying to parse an xml response using jquery.
Following is the xml content:
<?xml version=”1.0″ encoding=”utf-8″?>
<rows>
<row>
<cell>lib</cell>
<cell>19-06-2009 10:01:55</cell>
</row>
<row>
<cell>usr</cell>
<cell>19-06-2009 10:01:55</cell>
</row>
</rows>
This is a valid xml.
Following is the jquery ajax request:
function loadXML() {
$.ajax({
url: ‘xml.jsp’, //assume that the url parses the server directory and gives us the above shown xml
type: “GET”,
dataType: “xml”,
success: function(data) {
console.debug(“success”);
var rows = $(data).find(‘rows’);
//now parse each of the row in rows
$(rows).find(‘row’).each (
function() {
//now parse each of the cell in row
$(this).find(‘cell’).each (
function() {
var cellValue = $(this).text();
}
);
}
);
},
error: function(data) {
console.debug(data.status);
}
});
Everything seems so good until the program enters the error block of the ajax request.
The status displayed was 200.
It looks like some parser error when digged deep into the XMLResponse using firebug.
So what could be wrong?
It is actually the inclusion of header that was the problem.
If you have set the content-type as ‘text/xml’ then there is no need for a xml header.
Hope this could solve someone banging their head with this issue.
