【问题标题】:How do I get JSON data using Sencha如何使用 Sencha 获取 JSON 数据
【发布时间】:2023-04-01 15:43:02
【问题描述】:

Sencha 新手,我正在使用以下代码尝试获取 JSON 数据。由于某种原因,它返回 null,但我知道 URL 正在返回值,因为我在另一个项目中使用它。

// Make the JsonP request
        Ext.data.JsonP.request({
            url: 'http://xxx.azurewebsites.net/login',
            crossDomain: true,
            type: "GET",
            dataType: "json",
            callbackKey: 'jsoncallback',
            callback: function(successful, data ) {
                alert( JSON.stringify(data) );
            }
        });

谁能指出我错过了什么。

【问题讨论】:

  • 您的网址返回了什么?请记住,JSON-P 需要在函数中返回数据,使用 callbackKey 作为函数名。

标签: extjs jsonp


【解决方案1】:

你需要添加scope:this属性来调用回调函数,试试这样。

Ext.data.JsonP.request({
    url: 'http://xxx.azurewebsites.net/login',
    crossDomain: true,
    type: "GET",
    dataType: "json",
    callbackKey: 'callback',
    scope: this,
    callback: function (response, value, request) {
        var result = Ext.decode(response.responseText);
        alert(result.propertyName);
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多