Sencha touch 如何在Sencha Touch应用程序中调用JSONP请求
在我的sencha应用程序中,我需要调用jsonp请求而不是ajax请求,但我不知道如何编写它。因此,请为我提供jsonp请求的演示Sencha touch 如何在Sencha Touch应用程序中调用JSONP请求,sencha-touch,Sencha Touch,在我的sencha应用程序中,我需要调用jsonp请求而不是ajax请求,但我不知道如何编写它。因此,请为我提供jsonp请求的演示 感谢您Sencha文档中的JSON请求示例:) 以下是指向更多详细信息的链接: 检查以下代码是否对我正常工作:) Ext.define('APP.view.List'{ 扩展:“Ext.Container”, 要求:[ “Ext.data.JsonP” ], 配置:{ 可滚动:对, 项目:[{ xtype:'面板', id:'JSONP' }, { 停靠:“顶部”
感谢您Sencha文档中的JSON请求示例:) 以下是指向更多详细信息的链接:
检查以下代码是否对我正常工作:)
Ext.define('APP.view.List'{
扩展:“Ext.Container”,
要求:[
“Ext.data.JsonP”
],
配置:{
可滚动:对,
项目:[{
xtype:'面板',
id:'JSONP'
}, {
停靠:“顶部”,
xtype:'工具栏',
项目:[{
文本:“使用JSON-P加载”,
处理程序:函数(){
var panel=Ext.getCmp('JSONP'),
tpl=新的Ext.XTemplate([
'',
'',
'',
“{date}”,
'',
'',
'',
“{tempMaxF}°{tempMinF}°”,
'',
'',
''
]);
panel.getParent().setMasked({
xtype:“加载掩码”,
消息:“正在加载…”
});
Ext.data.JsonP.request({
网址:'http://free.worldweatheronline.com/feed/weather.ashx',
callbackKey:'callback',
参数:{
键:“23f6a0ab24185952101705”,
q:'94301',//帕洛阿尔托
格式:“json”,
天数:5天
},
回调:函数(成功,结果){
var weather=result.data.weather;
如果(天气){
面板更新TML(tpl.applyTemplate(天气));
}
否则{
警报('检索天气时出错');
}
panel.getParent().unmask();
}
});
}
}]
}]
}
});
请参阅此问题-[使用Sencha Touch的移动应用程序-JSON请求生成语法错误][1][1]:检查此问题:
Ext.data.JsonP.request({
url: 'http://free.worldweatheronline.com/feed/weather.ashx',
callbackKey: 'callback',
params: {
key: '23f6a0ab24185952101705',
q: '94301', // Palo Alto
format: 'json',
num_of_days: 5
},
success: function(result) {
//Your success function here...
}
});
Ext.define('APP.view.List', {
extend: 'Ext.Container',
requires: [
'Ext.data.JsonP'
],
config: {
scrollable: true,
items: [{
xtype: 'panel',
id: 'JSONP'
}, {
docked: 'top',
xtype: 'toolbar',
items: [{
text: 'Load using JSON-P',
handler: function() {
var panel = Ext.getCmp('JSONP'),
tpl = new Ext.XTemplate([
'<div class="demo-weather">',
'<tpl for=".">',
'<div class="day">',
'<div class="date">{date}</div>',
'<tpl for="weatherIconUrl">',
'<img src="{value}">',
'</tpl>',
'<span class="temp">{tempMaxF}°<span class="temp_low">{tempMinF}°</span></span>',
'</div>',
'</tpl>',
'</div>'
]);
panel.getParent().setMasked({
xtype: 'loadmask',
message: 'Loading...'
});
Ext.data.JsonP.request({
url: 'http://free.worldweatheronline.com/feed/weather.ashx',
callbackKey: 'callback',
params: {
key: '23f6a0ab24185952101705',
q: '94301', // Palo Alto
format: 'json',
num_of_days: 5
},
callback: function(success, result) {
var weather = result.data.weather;
if (weather) {
panel.updateHtml(tpl.applyTemplate(weather));
}
else {
alert('There was an error retrieving the weather.');
}
panel.getParent().unmask();
}
});
}
}]
}]
}
});