且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么IE7和IE8给我“访问被拒绝"?调用jQuery时?

更新时间:2023-02-20 09:22:07

由于 document.domain 以避免被Same Origin策略拒绝访问.

Making a call to a sub domain is seen as a different domain because of the Same Origin policy. Make sure that you are setting document.domain to avoid access denied with the Same Origin policy.

要同步document.domain,您需要在两个位置进行设置.添加一个用于设置域的脚本标签,然后您需要在页面上具有一个iframe,以便在另一个域上设置相同的内容.

To get the document.domain in sync you need to set it in two places. Add a script tag that set the domain, and you need to have an iframe on the page that sets the same thing on the other domain.

通过"www.example.com"进行Ajax调用并正在调用"ajax.example.com"的页面:

The page that the Ajax call is made from "www.example.com" and is calling "ajax.example.com":

<script type="text/javascript">
  document.domain = "example.com";
</script>
<iframe src="http://ajax.example.com/domainCode.html"></iframe>

"domainCode.html"将仅包含脚本标记

The "domainCode.html" would just contain the script tag

<html>
  <head>
    <script type="text/javascript">
      document.domain = "example.com";
    </script>
  </head>
  <body>
  </body>
</html>

有了这个,您应该能够在子域之间进行通话.

With that in place you should be able to talk between your sub domains.