我有一个应该从外部Web服务中消耗JSONP的面板。
模型/ VimeoModel.js
rpc.models.VimeoModel = Ext.regModel('rpc.models.VimeoModel', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'}
]
});
视图/ VideoView.js
rpc.views.VideoView = new Ext.Panel({
id: 'VideoView',
title: "Videos",
tpl: VimeoTemplate,
iconCls: "tv",
dockedItems: [{ xtype: "toolbar", title: "Videos"}],
store: 'rpc.stores.VimeoStore'
});
存储/ VimeoStore.js
rpc.stores.VimeoStore = new Ext.data.Store({
id: 'VimeoStore',
model: 'rpc.models.VimeoModel',
proxy: {
type: 'scripttag',
url: WebService.Url + WebService.Vimeo.Read,
reader: {
type: 'jsonp',
root: 'results'
}
},
autoLoad: true
});
模板/ VimeoTemplate.js
var VimeoTemplate = new Ext.XTemplate([
'<tpl for=".">',
'<div>',
'{title}',
'</div>',
'</tpl>'
]);
不幸的是,当页面加载时,VideoView中没有填充任何数据。
WebService请求如下所示
http://rpc.infinitas.ws/Vimeo/Read?_dc=1308067234445&limit=25&callback=stcCallback1001
它正在返回JSONP响应
stcCallback1001({"results":[{"id":25036464,"title":"Power of A Surrendered Li..."},{"id":25036610,"title":"Child Dedication June 2011"},{"id":24734142,"title":"Power of A Surrendered Li..."},{"id":24884833,"title":"Finance Update June 2011"},{"id":24587711,"title":"Papua, Indonesia Sharing ..."},{"id":24232427,"title":"ICHTHUS: Coming King"},{"id":23868560,"title":"ICHTHUS: Healer"},{"id":23486615,"title":"ICHTHUS: Sanctifier"},{"id":23211649,"title":"ICHTHUS: Saviour"},{"id":23867961,"title":"Elder Announcement re: Br..."},{"id":22998163,"title":"Triumph of Grace: Risen L..."},{"id":23687914,"title":"Triumph of Grace: Reignin..."},{"id":23692076,"title":"KINGDOM now: For Thine Is..."},{"id":23694183,"title":"KINGDOM now: Deliver Us F..."}],"success":true});stcCallback1001({"results":[{"id":25036464,"title":"Power of A Surrendered Li..."},{"id":25036610,"title":"Child Dedication June 2011"},{"id":24734142,"title":"Power of A Surrendered Li..."},{"id":24884833,"title":"Finance Update June 2011"},{"id":24587711,"title":"Papua, Indonesia Sharing ..."},{"id":24232427,"title":"ICHTHUS: Coming King"},{"id":23868560,"title":"ICHTHUS: Healer"},{"id":23486615,"title":"ICHTHUS: Sanctifier"},{"id":23211649,"title":"ICHTHUS: Saviour"},{"id":23867961,"title":"Elder Announcement re: Br..."},{"id":22998163,"title":"Triumph of Grace: Risen L..."},{"id":23687914,"title":"Triumph of Grace: Reignin..."},{"id":23692076,"title":"KINGDOM now: For Thine Is..."},{"id":23694183,"title":"KINGDOM now: Deliver Us F..."}],"success":true});
当我启动Chrome Javascript控制台时出现错误
阅读:1未捕获的ReferenceError:未定义stcCallback1001
如果您需要更多信息,这里是暂存应用程序 http://rpcm.infinitas.ws
答案 0 :(得分:2)
问题在于你要返回的javascript。您正在输出两次回调。如果单击问题中的jsonp链接,您应该看到两个stcCallback1001调用。由于回调在第一个之后被删除,第二个回失失败。
BTW您不需要指定callbackParam。
答案 1 :(得分:0)
请参阅我在其他问题上提供的答案Sencha Touch JSONP Store Data not showing up in Panel。
主要问题是您要将代理从type: 'scripttag'
更改为type: 'jsonp'
。一旦这样做,JSONP代理应该在向服务器发出请求之前创建适当的回调函数。
答案 2 :(得分:-1)
使读者从'jsonp到'json'的类型应该带回正确的结果。