gpt4 book ai didi

javascript - Access-Control-Allow-Origin - 尝试从 Wordpress 安装访问 JSON 时出错

转载 作者:行者123 更新时间:2023-11-30 07:59:26 25 4
gpt4 key购买 nike

我尝试使用来自 JavaScript (AngularJS) 的“旧”Json-Api 访问我的博客

现在我收到以下错误:

XMLHttpRequest cannot load http://example.com/?json=get_category_index. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

看起来很简单。但即使在我尝试了以下操作之后:

将这些行添加到 .htaccess 中:

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.php 和 json-api.php:

<? header("Access-Control-Allow-Origin: *"); ?>

我仍然遇到这个错误。

最佳答案

您可以在 AngularJS 中使用 JSONP

JSONP 用于从不同域的服务器请求数据。

已记录 here .

关于javascript - Access-Control-Allow-Origin - 尝试从 Wordpress 安装访问 JSON 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31972946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com