javascript - ExtJS : Getting the response from a JSONP proxy?

标签 javascript json extjs proxy

我有以下 Store,它应该通过 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);
        }
    }
});

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

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 响应?

最佳答案

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

定义存储类后,您应该创建它的一个实例,然后调用加载函数。 像这样

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

关于javascript - ExtJS : Getting the response from a JSONP proxy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39822359/

相关文章:

json - Apache NiFi ExecuteScript : Groovy script to replace Json values via a mapping file

arrays - 获取 JSON 数据以从数组填充 TableView

javascript - PHP json_encode 到 JS 对象数组

extjs - 如何在 ExtJS 的 Triggerfield 弹出窗口中放置一个组件?

ExtJS 4、Model中的dateFormat应该是什么?

javascript - 如何获取给定特征的图层

javascript - Chrome 扩展突出显示文本选择 chrome.tabs

javascript - Leaflet.js - 在 map View 上拟合 geoJSON 坐标

javascript - 如何在 ExtJS 中的 TreeGrid 的树节点中显示文本

javascript - Angular 的奇怪数组行为