Web services Can';无法使用scripttag代理和JSONP在Sencha Touch中运行数据存储
我有一个面板,它应该使用来自外部web服务的JSONP 模型/VimeoModel.jsWeb services Can';无法使用scripttag代理和JSONP在Sencha Touch中运行数据存储,web-services,json,sencha-touch,Web Services,Json,Sencha Touch,我有一个面板,它应该使用来自外部web服务的JSONP 模型/VimeoModel.js rpc.models.VimeoModel = Ext.regModel('rpc.models.VimeoModel', { fields: [ {name: 'id', type: 'int'}, {name: 'title', type: 'string'} ] }); rpc.views.VideoView = new Ext.Panel({
rpc.models.VimeoModel = Ext.regModel('rpc.models.VimeoModel', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'}
]
});
rpc.views.VideoView = new Ext.Panel({
id: 'VideoView',
title: "Videos",
tpl: VimeoTemplate,
iconCls: "tv",
dockedItems: [{ xtype: "toolbar", title: "Videos"}],
store: 'rpc.stores.VimeoStore'
});
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
});
var VimeoTemplate = new Ext.XTemplate([
'<tpl for=".">',
'<div>',
'{title}',
'</div>',
'</tpl>'
]);
视图/VideoView.js
rpc.models.VimeoModel = Ext.regModel('rpc.models.VimeoModel', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'}
]
});
rpc.views.VideoView = new Ext.Panel({
id: 'VideoView',
title: "Videos",
tpl: VimeoTemplate,
iconCls: "tv",
dockedItems: [{ xtype: "toolbar", title: "Videos"}],
store: 'rpc.stores.VimeoStore'
});
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
});
var VimeoTemplate = new Ext.XTemplate([
'<tpl for=".">',
'<div>',
'{title}',
'</div>',
'</tpl>'
]);
stores/VimeoStore.js
rpc.models.VimeoModel = Ext.regModel('rpc.models.VimeoModel', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'}
]
});
rpc.views.VideoView = new Ext.Panel({
id: 'VideoView',
title: "Videos",
tpl: VimeoTemplate,
iconCls: "tv",
dockedItems: [{ xtype: "toolbar", title: "Videos"}],
store: 'rpc.stores.VimeoStore'
});
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
});
var VimeoTemplate = new Ext.XTemplate([
'<tpl for=".">',
'<div>',
'{title}',
'</div>',
'</tpl>'
]);
templates/VimeoTemplate.js
rpc.models.VimeoModel = Ext.regModel('rpc.models.VimeoModel', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'}
]
});
rpc.views.VideoView = new Ext.Panel({
id: 'VideoView',
title: "Videos",
tpl: VimeoTemplate,
iconCls: "tv",
dockedItems: [{ xtype: "toolbar", title: "Videos"}],
store: 'rpc.stores.VimeoStore'
});
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
});
var VimeoTemplate = new Ext.XTemplate([
'<tpl for=".">',
'<div>',
'{title}',
'</div>',
'</tpl>'
]);
当我启动Chrome Javascript控制台时,我得到一个错误
读取:1未捕获引用错误:未定义stcCallback1001
如果您需要更多信息,这里是登台应用程序问题出在您返回的javascript中。您将输出两次回调。如果单击问题中的jsonp链接,您应该会看到两个stcCallback1001调用。由于回调在第一次回调之后被删除,因此第二次回调失败
顺便说一句,您不需要指定callbackParam。请参阅我在其他问题上提供的答案
主要问题是您希望将代理从
类型:'scripttag'
更改为类型:'jsonp'
。一旦这样做了,JSONP代理应该在向服务器发出请求之前创建适当的回调函数。将读取器类型从“JSONP”改为“json”应该会返回正确的结果 感谢您的回复,我尝试了您的建议,并更新了我的问题以澄清问题。不幸的是,我仍然处于困境。对不起,我以为这是一个随机数,结果是一致的stcCallback1001
-我将再次编辑我的问题。如果我向代理添加callbackParam:'idSession',
,则“未定义”错误消失,但我得到的是“TypeError:number不是函数”.我仍然得到错误。。。未捕获引用错误:stcCallback1001没有定义。啊,我现在明白你的意思了。我不知道这是怎么回事。还要注意,你需要从你的URL中删除回调
参数。JSONP代理将自己添加它。它创建了一个处理响应的函数,需要在请求参数中指定该函数。如果您也在设置它,那么服务器将以两个值结束,并且可能会出现异常行为,例如创建两个响应。为了防止跨域请求错误,需要jsonp。