在apache2本地服务器上使用jQuery检索RSS feed时遇到一些问题。我正在运行Mac OS X Catalina。当我运行此javascript时:
$.get('url', function (data) {
$(data).find("entry").each(function () { // or "item" or whatever suits your feed
var el = $(this);
console.log("------------------------");
console.log("title : " + el.find("title").text());
console.log("author : " + el.find("author").text());
console.log("description: " + el.find("description").text());
});
});
Chrome给我以下错误日志:
从来源“ http://localhost”访问“ URL”处的XMLHttpRequest具有 被CORS策略阻止:没有“ Access-Control-Allow-Origin”标头 在请求的资源上。
我的/apache2/users/*.conf
看起来像这样:
DocumentRoot "/Users/*/Sites/"
<Directory "/Users/*/Sites/">
Options FollowSymLinks Multiviews Indexes
AllowOverride All
MultiviewsMatch Any
Require all granted
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Header add Access-Control-Allow-Credentials "true"
Header always set Access-Control-Allow-Origin "*"
</Directory>
我还确保已安装mod_headers并重新启动apache:
$ httpd -M |grep header
$ sudo apachectl restart
我仍然抛出相同的错误。我已经阅读了所有可以找到的帖子,但仍然没有找到解决方案。任何帮助将不胜感激,谢谢。