KingJames
KingJames

Reputation: 556

JSONP request timeout in extjs

I am sending a jsonp request to localhost for getting a json data. But I am getting request timeout. I am not able to figure out the cause of timeout. Can anybody help me? Below is the function

init: function() {
    var me = this;
    //making the jsonp request to fetch data
    console.log("init start");
    Ext.data.JsonP.request({
      url : 'http://localhost/TwitterApp/resources/json/Data.json',
      success: function(response){
      //populating the data in the store
        //console.log("aaaa" + response);
        var store = me.getDataStore();
        store.loadData(response);
        //console.log("on Init" + store);
        me.getStatistics().renderColumnCharts(store);
      },
      failure: function(response){
        console.log(response);
      }
    });
},

This is Data.json file. and it is at the same location as specified in the code

[
{
    Hashtag: "Hello",
    Value: 1
},
{
    Hashtag: "Hi",
    Value: 4
},
{
    Hashtag: "Obama",
    Value: 61
},
{
    Hashtag: "Close",
    Value: 551
},
{
    Hashtag: "MOD",
    Value: 15
},
{
    Hashtag: "winter",
    Value: 51
},
{
    Hashtag: "chadar",
    Value: 71
},
{
    Hashtag: "bottle",
    Value: 17
},
{
    Hashtag: "jaiHo",
    Value: 154
},
{
    Hashtag: "Madhur",
    Value: 144
},
{
    Hashtag: "Plank",
    Value: 142
},
{
    Hashtag: "Gft",
    Value: 1
}
]

I tried inspecting network request. In showed json content form the file in the response body. But still it is going to failure function and giving timeout. Attached hereby is the screenshot Response screen shot

Upvotes: 3

Views: 1047

Answers (1)

mcv
mcv

Reputation: 4429

Your response doesn't look like jsonp. The point of jsonp is that it's executed as javascript, and the response had to wrap the data in a function call. Try sending this response:

callback([{Hashtag: "Hello",Value: 1}, ... ]);

I'm not sure how extjs handles jsonp requests. Usually, the name of the callback function is configurable, and the js framework handles this for you. Maybe you need to add ?callback=? to your url, or specify a callback name in your ext2 jsonp request. Maybe ext2 already passes a callback parameter to your server and you ignore it.

Upvotes: 2

Related Questions