PDA

View Full Version : Basic xml parse from Ajax.request?



druffus
12 Sep 2008, 10:56 AM
Hello all,

I thought this would be pretty standard and maybe it is, but i can't find any references to it.

I am sending an Ajax.request and on success sending it to the function. What I am retrieving is a simple xml file with various data (not a list - a single result).

I just want to be able to get at the data so that i can perform various tests and do other things with it.

so here is some code...




if(!result) {

control.last_project = id;
control.last_project_title = title;
Ext.Ajax.request({
url: '/projects',
success: projects.project_view,
params: { action: 'info', id: id }
});

} else {

var result = new Ext.data.XmlReader({
totalRecords: "RowCount",
record: "row",
}, result.responseText);

for(i in result){
alert(i + ' => ' + result[i]);
}

var result_records = result.read();

for(i in result_records){
alert(i + ' => ' + result[i]);
}

// get variables for this single result and use them

}



where i am just trying to send



<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<RowCount>1</RowCount>
<row>
<designer_id>{$project_info.designer_id}</designer_id>
<number_rooms>{$project_info.number_rooms}</number_rooms>
<more_data>{$project_info.number_rooms}</more_data>
</row>
</dataset>

hendricd
12 Sep 2008, 11:51 AM
var result = new Ext.data.XmlReader({
totalRecords: "RowCount",
record: "row",
}, result.responseXML);
and your server must set the Content-Type : 'application(or text)/xml' in the response for IE.

druffus
12 Sep 2008, 12:23 PM
Ok, thanks, that got me farther. But i keep getting an error that "A is undefined" on "Ext.data.XmlReader=function(A,B){A=A||{}...,records:Q,totalRecords:G||Q.length}}});"




var result_xml = new Ext.data.XmlReader({
totalRecords: "RowCount",
record: "row"
}, result.responseXML);

var result_records = result_xml.read();

for(i in result_records){
alert(i + ' => ' + result_records[i]);
}