2012-01-10 64 views
1

我是Sencha Touch的新手,我嘗試瞭解它如何與網絡服務配合使用。我的下面的代碼可以正常使用我在本地Web服務器上託管的xml文件。當我嘗試使用公共Web服務時,我什麼也得不到。這很奇怪,因爲xml文件是完全相同的,只有一個代碼字符串是不同的。我的意思是,如果要在Web服務器上承載以下xml文件,並將其設置爲代理的url,則一切都會好,並且會顯示數據。從Sencha Touch中使用商店中的網絡服務獲取xml數據

這裏是我的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文件的樣本(你會通過地址得到它: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> 

回答

0

您必須設置php代理跨越,這是我的代理調用一個xml谷歌webservice的例子:

型號:

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); 
} 

這個工作對我來說NIKEL

相關問題