gpt4 book ai didi

javascript - Angular $http.get 请求在 Auth0 登录后失败

转载 作者:行者123 更新时间:2023-12-03 06:22:29 24 4
gpt4 key购买 nike

我正在编写一个 Angular SPA 应用程序。 $http.get请求如下:

$http.get("http://localhost:8888/Treatments.php")
.then(function (response) {
$scope.treatments = response.data.records;
})
.catch(function (response) {
console.log("Error: " + response.status);
});

在正常情况下效果很好。当我使用 Auth0 服务对用户进行身份验证时,问题就出现了。成功登录后,当发出任何 $http.get 请求时,控制台中会出现以下错误:

XMLHttpRequest cannot load http://localhost:8888/Treatments.php. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

为什么会发生这种情况?我该如何纠正这种意外行为?

最佳答案

终于可以用了。问题在于允许 CORS。为了允许此类请求,我只需将以下行添加到我的 .htaccess 文件

Header set Access-Control-Allow-Origin "*"

这解决了所有问题。

关于javascript - Angular $http.get 请求在 Auth0 登录后失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807385/

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