Jenna Maiz
Jenna Maiz

Reputation: 812

ExtJS : Getting the response from a JSONP proxy?

I have the following Store that is suppose to load data via a JSONP proxy :

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);
        }
    }
});

From the network tab on the browser, I see that a response comes back(truncated):

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...

But the above callback function doesn't seem to be executed. What do I need to do in order to get the JSON response ?

Upvotes: 0

Views: 319

Answers (1)

fradal83
fradal83

Reputation: 2022

There's no "success" config on proxy ( see http://docs.sencha.com/extjs/6.0.2/classic/Ext.data.proxy.JsonP.html ).

After you defined your store class, you should create an istance of it, then call the load function. Like this

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

Upvotes: 2

Related Questions