在Web应用程序所在目录的.htaccess文件中添加/设置了访问控制的标头(drupal)。但是当使用jquery为它发出ajax请求时,控制台错误会显示以下消息:
XMLHttpRequest cannot load http://localhost/drupal/get/news.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://127.0.0.1:56687' is therefore not allowed access.
.htaccess是内部文件夹“drupal”,标题设置如下:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
任何帮助将不胜感激。
答案 0 :(得分:0)
XMLHttpRequest cannot load http://localhost/drupal/get/news.
以上意味着在您的Drupal CMS中,您的引用指向您的localhost 。我的猜测是你在本地构建了你的站点,然后迁移到了一个实时服务器,但是这样做了一些引用还没有改变。我建议您将 .sql 文件中的所有http://localhost
个实例替换为http://yourdomain.com
,因为这些文件是公开可用的,其他任何人都无法访问您的本地资源。外网。