gpt4 book ai didi

javascript - XMLHttpRequest 无法加载 https ://. .... 对于 $http post 请求,预检响应无效(重定向)

转载 作者:行者123 更新时间:2023-12-02 14:12:10 27 4
gpt4 key购买 nike

这是我的 angularjs $http post 请求

    $http({
method: 'POST',
url: 'https://...',
data: {matric:u.matric, faculty:u.faculty, department:u.department, level:u.level, password:u.password},


}).success(function(){
$scope.passwor = '';
$scope.erro = '';
$scope.matri = '';
$state.go('login');
}).error(function(error){
console.log(error);
$scope.erro = 'Please Try Again. Check Your Connection ';
$scope.matri =error.matric[0];
$scope.passwor =error.password[0];


}).finally(function() {
loader.hide();
});

我的 api 是用 lumen 编写的,我已经将 palanik/lumencors 添加到了所有路由中。我也在网上搜索解决方案,但似乎没有什么对我有用。请帮忙!!!.我的 Controller 中有这个

public function option()
{
return true;
}

这在我的route.php中

 $app->options('/', 'matricController@option');
$app->post('/','matricController@store');

此代码也返回 OPTIONS OK(200)

 public function handle($request, Closure $next) {
if ($request->isMethod('OPTIONS')) {
$response = new Response("", 200);
}
else {
$response = $next($request);
}
$this->setCorsHeaders($request, $response);
return $response;
}

最佳答案

当不执行“简单”请求时,浏览器会向服务器发送所谓的飞行前 OPTIONS 请求,您必须以状态 200 响应该请求。因此,仅设置 CORS header 是不够的。

我猜测您的服务器缺少 OPTIONS 请求的路由,并且可能会重定向到某个占位符或错误页面来响应?

您可以在MDN上阅读有关飞行前请求的更多信息。

关于javascript - XMLHttpRequest 无法加载 https ://. .... 对于 $http post 请求,预检响应无效(重定向),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39440142/

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