如何将sencha touch中的JSONP调用设置为同步?
我正在使用 sencha touch & 创建一个移动应用程序面临我使用的 JSONP 异步调用的问题,我想我可以使用同步调用来解决它,就像 Extjs 4.x 中的 Ajax 一样: Extjs 4 中的 Ajax 同步.x
是否可以在JSONP中设置同步调用? 或者是否有替代方法可以实现这一目标?
提前致谢 :)
I'm creating a mobile app using sencha touch & facing a problem in asynchronous call of the JSONP I use, and I think I can solve it using synchronous call just like Ajax in Extjs 4.x :
Ajax synchronous in Extjs 4.x
Is it possible to set synchronous calls in JSONP?
or is there an override to achieve that?
Thanks in Advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不久前我对此进行了广泛的研究,发现这是不可能的。这是因为 JsonP 中使用了脚本标记 hack。使用 JsonP 的唯一原因是为了解决跨域问题。要解决此问题,请使用常规 Json 并在您的网站上设置此标头,指定允许调用此网站的网站。
访问控制允许来源: http://foo.example
I looked into this quite extensively a while back, and found that it is not possible. This is because of the script tag hack used in JsonP. The only reason to use JsonP is to get around the cross-domain issues. To get around this using regular Json and set this header on your website specifying the sites that are allowed to make calls to this site.
Access-Control-Allow-Origin: http://foo.example
类别 = 新 Ext.data.Store({
模型:'类别',
自动加载:真,
代理人: {
类型:'ajax',
url: 'http://localhost/php/server.php?action=catall',
读者:{
类型:'json'
}
}
});
它是 json 数据
[{"catname":"健康","id":"1"},{"catname":"IMAGINE","id":"2"},{"catname":"娱乐","id": "3"},{"catname":"KIDS","id":"4"},{"catname":"LOCAL","id":"5"},{"catname":"旅行者","id":"6"},{"catname":"互联网","id":"7"}]
categories = new Ext.data.Store({
model: 'categories',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://localhost/php/server.php?action=catall',
reader: {
type: 'json'
}
}
});
its the json data
[{"catname":"HEALTH","id":"1"},{"catname":"IMAGINE","id":"2"},{"catname":"ENTERTAINMENT ","id":"3"},{"catname":"KIDS","id":"4"},{"catname":"LOCAL","id":"5"},{"catname":"TRAVELLER ","id":"6"},{"catname":"INTERNET ","id":"7"}]