阿贾克斯:预检

时间:2018-03-06 22:19:41

标签: javascript php laravel

我尝试将表单从hist(a, breaks=c(0, 1, 2, max(a)), right=FALSE, include.lowest=TRUE) 发布到example.com但我收到错误。

  

对预检请求的响应没有通过访问控制检查:否'访问控制 - 允许 - 来源'标头出现在请求的资源上。起源' http://hablow.net'因此不允许访问。响应的HTTP状态代码为403。

我已经从here

安装了Laravel Cors软件包
api.example.com

我已尝试在PHP中手动添加标题...

<?php
return [
     /*
     |--------------------------------------------------------------------------
     | Laravel CORS
     |--------------------------------------------------------------------------
     |
     | allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
     | to accept any value.
     |
     */
    'supportsCredentials' => false,
    'allowedOrigins' => ['*'],
    'allowedHeaders' => ['Origin', 'Content-Type', 'X-Requested-With'],
    'allowedMethods' => ['*'], // ex: ['GET', 'POST', 'PUT',  'DELETE']
    'exposedHeaders' => [],
    'maxAge' => 0,
];

我尝试过什么似乎都失败了?继承我的AJAX

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');

1 个答案:

答案 0 :(得分:0)

您需要配置Web服务器以允许cors请求。以下是使用ngnix的方法:

https://enable-cors.org/server_nginx.html

对于Apache2

https://enable-cors.org/server_apache.html