How to access jsonp data using Ext.util.JSONP.requ

2019-09-08 07:13发布

I am very new to sencha touch application, i've been tasked to get the json data from a cross domain and data looks like below

 { "data": { "error": [ {"msg": "Free API has moved to
 free.worldweatheronline.com\/feed\/weather.ashx url.
 Please make changes at your end. Please contact support team at
 info@worldweatheronline.com for any other issues." } ] }}

How to trigger a callback function for this json data,i can able to request but the callback function is not triggering.Can anyone help me out in this?thanks in advance

1条回答
Anthone
2楼-- · 2019-09-08 07:57

Are you using JSONP request this way?

Ext.data.JsonP.request({
   url: 'YOUR JSONP URL',
   callbackName: 'someCallbackFunctionName',
   success: function(data) {
       console.log(data);
   }
});

And you have to wrap the data you are returning in a function whose name you are passing as "callbackName" config. So, the data you will send from server must look like this:

someCallbackFunctionName({ "data": { "error": [ {"msg": "Free API has moved to
 free.worldweatheronline.com\/feed\/weather.ashx url.
 Please make changes at your end. Please contact support team at
 info@worldweatheronline.com for any other issues." } ] }})

Do check the jsonp details in Sencha API.

查看更多
登录 后发表回答