【问题标题】:Sencha Touch - Error - JSON RecoverySencha Touch - 错误 - JSON 恢复
【发布时间】:2011-08-18 14:13:42
【问题描述】:

我与您联系是因为我陷入了僵局。 我尝试使用“ScriptTag”从外部网络服务获取数据,但它不起作用,因为网络服务返回简单的 json 格式(无 JSONP)。

您知道是否有另一种使用 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'
                        },                      
                    }
                }),
                
            },
        ],
                        
    });

}

});

警告:资源解释为脚本,但使用 MIME 类型 application/json 传输。

错误:未捕获的 SyntaxError:意外令牌:

谢谢。

凯文。

【问题讨论】:

    标签: javascript json sencha-touch script-tag


    【解决方案1】:

    您正在寻找的是Ajax Proxy。文档中有一些关于如何使用它以及如何配置它的示例。默认阅读器是 JSON,因此只要您的模型与通过 JSON 检索到的信息匹配,就可以了。

    您应该注意的另一件事是,JSONP 可以绕过跨站点脚本,但如果您不部署到 walker.hotcity.lu 域,则浏览器将由于 @987654322 而不允许该请求@。服务器必须使用正确的 CORS 标头进行响应,以允许您的应用访问数据。

    【讨论】:

      猜你喜欢
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      相关资源
      最近更新 更多