I am trying to do authorization using JavaScript by connecting to the RESTful API built in Flask .
(我试图通过连接到Flask内置的RESTful API来使用JavaScript进行授权。)
However, when I make the request, I get the following error: (但是,当我发出请求时,出现以下错误:)
XMLHttpRequest cannot load http://myApiUrl/login .
(XMLHttpRequest无法加载http:// myApiUrl / login 。)
No 'Access-Control-Allow-Origin' header is present on the requested resource. (所请求的资源上没有“ Access-Control-Allow-Origin”标头。)
Origin 'null' is therefore not allowed access. (因此,不允许访问原始“空”。)
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);
});
ask by Mr Jedi translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…