为什么我的JavaScript在所请求的资源上出现“No'Access-Control-Allow-Origin'标头”错误,当Postman没有?

I am trying to do authorization using JavaScript by connecting to the RESTful API built in Flask. However, when I make the request, I get the following error:

我试图通过连接到Flask内置的RESTful API来使用JavaScript进行授权。但是,当我发出请求时,我收到以下错误:

XMLHttpRequest cannot load http://myApiUrl/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

XMLHttpRequest无法加载http:// myApiUrl / login。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许原点'null'访问。

I know that the API or remote resource must set the header, but why did it work when I made the request via the Chrome extension Postman?

我知道API或远程资源必须设置标题,但为什么在我通过Chrome扩展程序Postman发出请求时它可以正常工作?

This is the request code:

这是请求代码:

$.ajax({    type: "POST",    dataType: 'text',    url: api,    username: 'user',    password: 'pass',    crossDomain : true,    xhrFields: {        withCredentials: true    }})    .done(function( data ) {        console.log("done");    })    .fail( function(xhr, textStatus, errorThrown) {        alert(xhr.responseText);        alert(textStatus);    });

38 个解决方案:https://www.itdaan.com/blog/2013/11/17/3282e36c81f229c7fc67344781b5f50e.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值