设置访问控制的跨域Ajax请求 [英] Setting up access-control for cross-domain ajax request

查看:208
本文介绍了设置访问控制的跨域Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个子领域,即 a.xyz.com,b.xyz.com,c.xyz.com。现在,我有大约20 Ajax请求要在身体的onload发 a.xyz.com。

I have three sub-domains namely, a.xyz.com, b.xyz.com, c.xyz.com. Now, I have about 20 ajax request to be made on body onload of a.xyz.com.

所以,我认为平均分配20个请求上述三个域之间的。我试了一下穿越这片片段中 b.xyz.com c.xyz.com 中的.htaccess。然而,从a.xyz.com请求任何其他子域仍然被情人抛弃。

So, I thought of distributing 20 requests equally among the three domains above. I tried it through this piece of snippet in .htaccess of b.xyz.com and c.xyz.com. However, the request from a.xyz.com to any other sub-domain is still getting dumped.

<IfModule mod_headers.c>
   <FilesMatch "\.(php)$">
    Header set Access-Control-Allow-Origin: http://a.xyz.com,http://b.xyz.com,http://b.xyz.com
    Header set Access-Control-Allow-Methods : POST,GET,OPTIONS
</FilesMatch>
  </IfModule>

我已经把上面的的.htaccess 文件在我的子域 b.xyz.com c.xyz.com

I have placed the above .htaccess file in my subdomains b.xyz.com and c.xyz.com.

所以,任何人都可以predict什么是错在我的方法?

So, can anyone predict whats wrong in my approach ?

谢谢!

推荐答案

试试这个允许跨域所有xyz.com子域:

Try this to allow cross domain on all xyz.com subdomains:

SetEnvIf Origin "http(s)?://(.+\.)?(xyz\.com)$" ORIGIN_DOMAIN=$0
<FilesMatch "\.(php)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin %{ORIGIN_DOMAIN}e env=ORIGIN_DOMAIN
    Header set Access-Control-Allow-Methods "POST,GET,OPTIONS"
  </IfModule>
</FilesMatch>

这篇关于设置访问控制的跨域Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆