ajax跨域请求
由于 Ajax 请求出于安全原因受到限制,因此没有太多内容,只需遵循规则即可,嗯..但我已经与此交叉:
https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript
据记载,如果您正在使用同一域的子域,则可以使用以下 JavaScript“绕过”这些规则line :
document.domain = "company.com";
我还没有尝试过,因为我不知道这是否只适用于(完美适用)任何其他浏览器,或者至少适用于主要浏览器。是否可以?
谢谢。
Since Ajax requests are limited for security reasons, there's not much to it, just follow the rules eh .. but I've crossed with this :
https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript
It's written that you can "bypass" those rules, in case you're working with subdomains of the same domain, with the following javascript line :
document.domain = "company.com";
I haven't tried it yet, since I don't know if this only works (perfectly works) with any other browser, or at least the major ones. Is it possible?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用 JSONP 进行跨域请求。它相对易于使用,允许您从任何支持回调的服务器/脚本请求任何内容(只要是 JSON 格式)。 JSONP 的好处是,它可以在较旧的浏览器中运行,这与许多其他解决方案不同。
正如 Matthew Abbott 在评论中指出的那样,唯一严重的限制似乎是它始终使用 HTTP GET 方法。
I would recommend JSONP for cross-domain requests. It is relatively easy to use and allows you to request anything (as long as it is in JSON format) from any server/script that supports the callback. The good thing about JSONP is, that it works in older browsers, unlike many of the other solutions.
The only serious limitation seems to be that it always uses the HTTP GET method, as Matthew Abbott pointed out in the comments.
如果您可以控制其他域,则可以使用CORS。 (是的,我知道这并不能回答您的实际问题。抱歉,我能尽力而为。)
If you have control of the other domain, you can use CORS. (Yes, I know this doesn't answer your actual question. Sorry, best I could do.)
根据记录,document.domain 有效。但是,由于某种原因,它不支持子域。
For the record, document.domain works. However, it doesn't support subdomains for some reason.