WordPress中的访问控制 - 允许原素

发布于 2025-01-23 12:03:02 字数 274 浏览 2 评论 0原文

我将以下代码添加到我的function.php中,

function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');

但是当我运行Web应用程序时,会收到以下错误:

XMLHttpRequest error.

I add the following code to my function.php

function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');

But when i run my web application get the following error:

XMLHttpRequest error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2025-01-30 12:03:02

要修复Access-Control-Allow-Origin,您必须从.htaccess进行操作。这是要添加到该文件的代码以及参考文章,该代码更深入地解释了错误。

https://crunchify.com/how-to-fix-access-control-allow-oryigin-origin-sissue-for-your-https-enabled-wordpress-wordpress-site-site-site-and-maxcdn/

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

To fix Access-Control-Allow-Origin, you have to do it from .htaccess. Here is the code to add to that file as well as the reference article, which explains the error in more depth.

https://crunchify.com/how-to-fix-access-control-allow-origin-issue-for-your-https-enabled-wordpress-site-and-maxcdn/

<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)
quot;>
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文