【问题标题】:ExtJS : Getting the response from a JSONP proxy?ExtJS:从 JSONP 代理获取响应?
【发布时间】:2016-10-02 22:25:41
【问题描述】:

我有以下商店,假设通过 JSONP 代理加载数据:

Ext.define('Forecaster.store.WeatherDay', {
    extend : 'Ext.data.Store',
    model : 'Forecaster.model.WeatherDay',
    autoLoad : true,
    proxy : {
        type : 'jsonp',
        method : 'GET',
        url : 'http://api.wunderground.com/api/[myAPIKey]/forecast10day/q/11432.json',
        root: 'forecast',
        dataType : 'json',
        success: function (result, request) {
            //success
            console.log("Sucess!");
            console.log(result, request);
        }
    }
});

从浏览器的网络选项卡中,我看到响应返回(截断):

Ext.data.JsonP.callback1(
{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "forecast10day": 1
  }
    }
        ,
    "forecast":{
        "txt_forecast": {
        "date":"5:18 PM EDT",
        "forecastday": [
        {
        "period":0,
        "icon":"cloudy",
        "icon_url":"http://icons.wxug.com/i/c/k/cloudy.gif",
         ...more of the response...

但是上面的回调函数好像没有执行。我需要做什么才能获得 JSON 响应?

【问题讨论】:

    标签: javascript json extjs proxy


    【解决方案1】:

    代理上没有“成功”配置(请参阅http://docs.sencha.com/extjs/6.0.2/classic/Ext.data.proxy.JsonP.html)。

    在你定义了你的 store 类之后,你应该创建它的一个 istance,然后调用 load 函数。 像这样

    var store = Ext.create('Forecaster.store.WeatherDay');
    store.load({
            success: function (result, request) {
                //success
                console.log("Sucess!");
                console.log(result, request);
            }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-06
      • 2014-02-24
      相关资源
      最近更新 更多