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

浪子不回头ぞ 提交于 2019-12-12 02:47:55

问题


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:


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.



来源:https://stackoverflow.com/questions/9596166/how-to-access-jsonp-data-using-ext-util-jsonp-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!