2011-05-04 69 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标题做出响应,以允许您的应用程序访问数据。