I thought cross-subdomain AJAX requests were allowed, but this Chrome error seems to indicate otherwise

前端 未结 2 1472
粉色の甜心
粉色の甜心 2020-12-09 04:10

I know that cross-domain requests are disallowed for security reasons, but I was under the impression that only the top-level domain needed to match, that different sub-doma

相关标签:
2条回答
  • 2020-12-09 04:35

    In short, the rules of the same origin policy are:

    • same host
    • same port
    • same protocol

    In your example you are violating the host rule, as a different subdomain could point to a different host/ IP than another, even if the second level domain is the same.

    If you have no other possibility, you could try to use JSONP in your ajax request; this doesn't have an SOP.

    Reference

    0 讨论(0)
  • 2020-12-09 04:51

    No cross sub domain requests are not allowed in any browser. But there are some ways like CORS, using iframes, setting document.domain to make it work (although with some limitations).

    0 讨论(0)
提交回复
热议问题