API获取请求在邮递员中有效,但在jQuery Ajax中被CORS策略阻止

时间:2020-04-24 02:04:37

标签: php jquery ajax api cors

AJAX请求中的错误

http://localhost”已被CORS政策阻止:对预检请求的响应未通过访问控制检查:所请求的资源上没有“ Access-Control-Allow-Origin”标头

我的密码

var srv_url = 'https://api-domain.com/api/index.php?type=join&meetingID=test01&moderatorPW=mp&fullName=John';
    var auth_token = 'e6a83f2844c9cdd4729b69dc851f96c1c073a23b4f37eb7cdec83bf8c9c7a06d'

    $.ajax({
      url: srv_url,
      type: 'get',
      beforeSend: function(xhr){
        xhr.setRequestHeader("Authorization", auth_token);
      },
      success: function(res){
        console.log(res)
      },
      error: function(e){
        console.log(e)
      }
    })

但要在邮递员中工作

enter image description here

如果存在与CORS相关的问题,为什么此请求在 同一台机器上的邮递员。请帮我,我在做什么吗 我的Ajax代码错误。

1 个答案:

答案 0 :(得分:0)

您需要允许使用以下命令在服务器端进行跨源访问:

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

您将找到更多详细信息here