我是新来的Sencha,我试着理解它是如何与网络服务一起工作的。下面的代码可以很好地处理我在本地web服务器上托管的xml文件。当我尝试使用公共网络服务时,我什么也得不到。这很奇怪,因为xml文件是完全相同的,只有一个代码字符串是不同的。我的意思是,如果将以下xml-文件托管在web服务器上并将其设置为代理的url,则一切都将正常,数据将显示出来。
这是我的js代码:
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);
}
});下面是xml-file的示例(您将通过地址: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>发布于 2012-12-04 14:25:17
您必须设置一个php代理来进行交叉操作,这是我的代理调用的一个例子:
模型:
Ext.regModel('ModelTrajectoire', {
fields: [
{
name: 'lat',
},
{
name: 'lng'
}
]
});商店:
var StoreTrajectoire = new Ext.data.Store({
model : 'ModelTrajectoire',
autoLoad: true,
storeId: 'StoreTrajectoire',
proxy: {
type:'ajax',
url: 'proxy.php',
reader: {
type: 'xml',
record: 'step'
}
}
});proxy.php :
// type de retour
header('Content-type: text/xml');
// URL
$requestURL = "http://maps.googleapis.com/maps/api/directions/xml?origin=Chicago,IL&destination=Los+Angeles,CA&sensor=false" ;
//Getting data from URL requested
$handle = fopen($requestURL, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}这对我来说很管用
https://stackoverflow.com/questions/8812034
复制相似问题