PDA

View Full Version : Show in list xml data from web service using store



s.t.a.s
11 Jan 2012, 1:14 PM
Hi, everyone! I'm newbie in Sencha Touch and I want to understand how it works with web services. My following code works fine with the xml file I hosted on my local web server. But, when I try to work with public web service, I get nothing. It's strange, cause xml files are absolutely the same and only one string of the code is different (only url). I mean, if to host the following xml file on web server and to set it as url of proxy, all'll be OK and data will be shown. But when to set url as 'http://www.thomas-bayer.com/sqlrest/INVOICE/605', which returns the same xml, you'll get nothing.


Here is my js-code:



Ext.require([
'Ext.Panel',
'Ext.tab.Panel',
'Ext.Ajax'
]);

Ext.application({
name: 'Sencha',

launch: function() {
Ext.regModel('XMLUser', {
fields: ['ID', 'CUSTOMERID', 'TOTAL']
});
var XMLStore = new Ext.data.Store({
model: 'XMLUser',
implicitIncludes: true,
method:'get',
proxy: {
type: 'ajax',
url : 'http://www.thomas-bayer.com/sqlrest/INVOICE/605',
//url: 'test1.xml',
reader: {
type : 'xml',
record: 'INVOICE'
}
},
autoLoad: true
});
var XMLTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="id-class" id="{ID}">{ID}',
'<div>{CUSTOMERID}',
'<div>{TOTAL}',
'</tpl>'
);

Ext.create("Ext.TabPanel", {
fullscreen: true,
tabBarPosition: 'bottom',
items: [
{
xtype: 'list',
title: 'Blog',
iconCls: 'home',
itemTpl: XMLTpl,
store: XMLStore,
singleSelect : true
}
]
}).setActiveItem(0);
}
});
Here is the sample of xml-file (and you will get it by address: http://www.thomas-bayer.com/sqlrest/INVOICE/605):





<?xml version="1.0"?><INVOICE xmlns:xlink="http://www.w3.org/1999/xlink">
<ID>605</ID>
<CUSTOMERID xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/505/">505</CUSTOMERID>
<TOTAL>209505</TOTAL>
</INVOICE>

mitchellsimoens
11 Jan 2012, 1:50 PM
So this is cross origin? browsers put security restrictions on ajax calls

s.t.a.s
11 Jan 2012, 11:14 PM
Hmmmm.Is there any option to turn this policy off (I tested it in Chrome and Firefox)? And how to provide this fact?

mitchellsimoens
12 Jan 2012, 5:45 AM
No, there is no way. If you were using JSON in stead of XML then you could use the JsonP which allows cross-origin.