Reputation: 4281
I am trying to get my xml data by using ajax call. But I am getting only ROOT Node value data in my result.responseXML
. Not able to access ITEM tag data.
My XML.
<ROOT UN="ABC" Total="28">
<ITEM Val = "1" data = "name1" />
<ITEM Val = "2" data = "name2" />
<ITEM Val = "3" data = "name3" />
<ITEM Val = "4" data = "name4" />
<ITEM Val = "5" data = "name5" />
</ROOT>
Here is what I am trying.
Ext.Ajax.request({
url : url,
method: 'GET',
success: function ( result, request )
{
debugger;
result.responseXML
}
});
In responseXML I am getting <ROOT UN="ABC" Total="28" ></ROOT>
Can Anybody help me what I am doing wrong and how to coorrect that. How to get Item tag also.
Upvotes: 0
Views: 614
Reputation: 221
In Ext js, the best way to read xml data is to use a store.
var itemStore = Ext.create('Ext.data.Store', {
fields: [{name: 'val', mapping: '@Val'},
{name: 'data', mapping: '@data'}],
proxy: {
type: 'ajax',
url: 'data1.xml',
method: 'GET',
reader: {
type: 'xml',
record: 'ITEM',
rootProperty: 'ROOT'
}
}
});
itemStore.load(function(records, operation, success) {
var item1 = itemStore.first();
console.log("First item " + item1.get('val'));
});
Check the fiddle here: https://fiddle.sencha.com/#view/editor&fiddle/1vd6
Upvotes: 3