我有一个Laravel应用程序,除了托管在AWS服务器上的excel Api之外,所有Api都运行良好。

以下是我在excel上传或任何类型的上传中遇到的错误。

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/products. (Reason: CORS preflight channel did not succeed).

以下标头已添加到bootstrap / app.php中

header('Access-Control-Allow-Origin: http://localhost');
header('Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS,PATCH');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Access-Control-Allow-Credentials': 'true');

我不确定配置有什么问题,因为为什么只有一个api会与其他api分开出现故障。

还附加了ajax脚本

$.ajax({
 type: frm.attr('method'),
 url: 'SERVER_URL',
 data: formData,
 crossDomain: true,
 dataType: "multipart/form-data",
 processData: false,  // tell jQuery not to process the data
 contentType: false,  // tell jQuery not to set contentType
 headers: {
      'Accept':'multipart/form-data',
      'contentType':'Application/json'
  },
  beforeSend: function (xhr) {
   xhr.setRequestHeader("Authorization", "Bearer AUTH_KEY")
 },
 dataType: "json",
 success: function (data) {
         console.log(data);
    },
    error: function (data) {
         console.log(data);
    }
});

以下是网络图片

enter image description here

enter image description here