javascript跨域问题
我正在构建一个小部件,将其提供给用户以嵌入到他们的网站和博客中。现在,该小部件在从我的服务器嵌入的页面中加载一个 javascript 文件,该文件又将 xmlhttp 请求放回到我的服务器以获取数据。由于安全原因,此请求在放置在其他服务器(我的服务器除外)上时会被阻止。我需要一个解决方案。
我已经搜索了很多解决方案。
我确信我不能在此处使用代理解决方案,因为运行脚本的域不受我控制。
另外,由于搜索引擎的原因,我无法使用 iframe。
可能的解决方案是什么?
谢谢,
快乐哈迪克
I am building a small widget that I am giving to users to embed in their websites and blogs. Now the widget loads a javascript file in the page where it is embedded from my server, which in turn puts an xmlhttp request back to my server to obtain data. Due to security reasons this request is being blocked when placed on other server (except my server). I need a solution to this.
I have searched a lot for a solution.
I am sure I cannot use the proxy solution here as the domains on which the script will be running is not controlled by me.
Also, I cannot use iframe due to Search engines.
What could be a possible solution?
Thanks,
happyhardik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,使用 JSONP 是执行此操作的唯一方法。
不过,我不明白:如果您的小部件是 JavaScript 驱动的,那么它无论如何都不会出现在任何搜索引擎中,不是吗?
To my knowledge, using JSONP is the only way to do this.
This I don't understand, though: If your widget is JavaScript driven, it won't turn up in any search engines anyway, will it?
这几乎是任意数量的相关查询的重复。例如
跨域脚本问题& JSONP
基本上你想使用 JSONP。
编辑:我看到佩卡已经说过了。
This is pretty much a duplicate of any number of related queries. e.g.
Cross Domain Scripting Issues & JSONP
Basically you want to use JSONP.
EDIT: I see Pekka has already said this.
由于同源政策,浏览器不支持跨域ajax请求。您可以查看此 JavaScript 库:ACD。
Browsers do not support cross domain ajax requests due same origin policy. You can check out this javascript library: ACD.