2011-05-04 68 views
0

我與您聯繫,因爲我處於僵局。 我嘗試使用「ScriptTag」從外部Web服務獲取數據,但它不起作用,因爲Web服務返回簡單的json格式(無JSONP)。Sencha Touch - 錯誤 - JSON恢復

你知道是否有另一種方法來使用sencha檢索json嗎?

var helloWorld = new Ext.Application({ 

Parking: Ext.regModel('Parking', { 
    fields:[ 
     {name:'parkingName'}, 
     {name:'latitude'}, 
     {name:'longitude'}, 
     {name:'mapUrl'} 
    ], 
}), 

launch: function() { 
    this.tabs = new Ext.TabPanel({ 
     fullscreen: true, 
     dockedItems: [{xtype:'toolbar', title:'JSON Recovery'}], 
     tabBar: { 
      ui: 'light', 
      layout: { 
       pack: 'center' 
      } 
     }, 
     items: [ 
      {cls:'Page1', title:'Page1', html:'Page1'}, 
      { 
       cls: 'list', 
       title: 'Page2', 
       xtype: 'list', 
       loadingText: 'Chargement', 
       itemTpl:'<div>{parkingName}</div>', 
       store: new Ext.data.Store({ 
        autoLoad:true, 
        model: 'Parking', 
        proxy: { 
         type: 'scripttag', 
         url : 'http://walker.hotcity.lu/hotcity-central-server/webresources/parking/json?format-version=1_0&client-type=iPhone', 
         reader: { 
          type: 'json', 
          root: 'remoteObject' 
         },      
        } 
       }), 

      }, 
     ], 

    }); 

} 

});

warning : Resource interpreted as Script but transferred with MIME type application/json.

error : Uncaught SyntaxError: Unexpected token :

謝謝。

Kevin。

回答

0

你在找什麼是Ajax Proxy。文檔中有一些關於如何使用它的例子,以及如何配置它。默認閱讀器是JSON,只要您的模型與通過JSON檢索的信息相匹配,那麼您就可以。

你應該知道的另一件事是,JSONP可以解決跨站腳本問題,但是如果你沒有部署到walker.hotcity.lu域,那麼瀏覽器將不會允許請求,因爲same origin policy 。服務器必須使用正確的CORS標題做出響應,以允許您的應用程序訪問數據。