[英]javascript cross-domain issue
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.
现在,该小部件将javascript文件加载到从我的服务器嵌入的页面中,这又将xmlhttp请求放回我的服务器以获取数据。 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. 另外,由于搜索引擎的原因,我无法使用iframe。
What could be a possible solution? 有什么可能的解决方案?
Thanks, 谢谢,
happyhardik 快乐哈迪克
To my knowledge, using JSONP is the only way to do this. 据我所知,使用JSONP是实现此目的的唯一方法。
Also, I cannot use iframe due to Search engines.
另外,由于搜索引擎的原因,我无法使用iframe。
This I don't understand, though: If your widget is JavaScript driven, it won't turn up in any search engines anyway, will it? 不过我不明白这一点:如果您的小部件是JavaScript驱动的,无论如何它都不会在任何搜索引擎中打开,对吗?
This is pretty much a duplicate of any number of related queries. 这几乎是任何数量的相关查询的重复。 eg
例如
Cross Domain Scripting Issues & JSONP 跨域脚本问题和JSONP
Basically you want to use JSONP. 基本上,您想使用JSONP。
EDIT: I see Pekka has already said this. 编辑:我看到Pekka已经说过了。
Browsers do not support cross domain ajax requests due same origin policy . 浏览器不支持跨域ajax请求,原因是同源策略相同 。 You can check out this javascript library: ACD .
您可以签出以下JavaScript库: ACD 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.