Sencha Touch跨域jsonp返回语法错误

碎豆

我有以下代码从另一个域检索JSON结构并将其显示在页面上。

但是,什么都没有出现,并且我在控制台中收到此错误:

未捕获的SyntaxError:意外令牌:People.json:2

我已经将JSON传递给JSON验证器,并且返回为有效。

这是我的代码:

    Ext.define("Person", {
        extend: "Ext.data.Model",
        config: {
            fields: [
                { name: 'Id', type: 'int'},
                { name: 'Name', type: 'string'},
                { name: 'Email', type: 'string'}
            ]
        }
    });

    var myStore = Ext.create("Ext.data.Store", {
        model: "Person",
        proxy: {
            type: "jsonp",
            url: 'http://example.com/People.json',
            reader: {
                type: "json",
                rootProperty: "Person"
            }
        },
        autoLoad: true
    });

    Ext.create("Ext.List", {
        fullscreen: true,
        store: myStore,
        itemTpl: "{Name}, {Id}"
    });

这是我的JSON文件的内容:

{
    "Person": [
        {
            "Id": 0,
            "Name": "Robert Lara",
            "Email": "[email protected]"
        },
        {
            "Id": 1,
            "Name": "Tom Hicks",
            "Email": "[email protected]"
        }
    ]
}
MDerks

JSONP并不是从字面上传输JSON,它http://example.com/People.json应该是调用回调函数的Javascript文件。

您已经使用Sencha处理了JSONP的客户端部分,但是您必须准备服务器端才能使用它。

JSONP上Sencha文档在“在服务器端实现”标题下有一个段落和一些代码示例

另外这个StackOverflow的问题说明了什么JSONP是怎么一回事。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章