Javascript callback for Sencha Touch proxy

Javascript callback for Sencha Touch proxy

本文关键字:Touch proxy Sencha for callback Javascript      更新时间:2023-09-26

我不明白如何从Sencha Touch中的另一个域获取信息。我想用从javascript检索到的数据填充我的商店,这些数据从另一个Web服务获取信息。

为了进行测试,我在simpleTest.js中编写了以下代码:

function hello(){
"test":[{ "text": "hello"}];
}

商店看起来像这样:

Ext.define("AccessibleMap.store.Teststore", {
    extend: "Ext.data.Store",
    config: {
        model: "AccessibleMap.model.Testmodel",
        autoLoad: true,
        proxy:{
            type: 'jsonp',
            url: 'http://test.accessiblemap.square7.ch/live%20access/scripts/simpleTest.js',
            reader:{
                type : 'json',
                rootProperty : 'test'
            }
        }
    }
});

错误消息显示找不到该页面。

Uncaught SyntaxError: Unexpected token :            simpleTest.js:2  

问题似乎是回调。我该如何解决这个问题?

如何在 javascript 中创建回调?我需要用 json 将返回的字符串字符串化吗?

你需要告诉 JavaScript 输出 json,你不能只写进去。您的代码应该是:

function hello(){
    document.write('{"test":[{ "text": "hello"}]}');
}

您的 json {} 周围也缺少大括号

当您开始实际编写正确的回调时,还需要注意其他一些事项。您可以使用 Ext.JSON 类来编码/解码 json(Ext.JSON.encode/Ext.JSON.decode)。我个人使用 PHP 后端,只使用本机 PHP 函数来吐出我的 json。