ajax跨域请求

发布于 2024-10-10 01:55:23 字数 422 浏览 0 评论 0原文

由于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风也等你 2024-10-17 01:55:23

我建议使用 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.

錯遇了你 2024-10-17 01:55:23

如果您可以控制其他域,则可以使用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.)

ζ澈沫 2024-10-17 01:55:23

根据记录,document.domain 有效。但是,由于某种原因,它不支持子域。

For the record, document.domain works. However, it doesn't support subdomains for some reason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文