而Postman就没问题?
我正在尝试通过连接到内置在 Flask 中的 RESTful API 来使用 JavaScript 进行授权。 但是,当我提出请求时,我会得到以下错误:
无法加载 http://myapiurl/login。 请求的资源上没有“访问控制允许原点”头。 因此,“ null”是不允许访问的。
我知道 API 或远程资源必须设置表头,但为什么当我通过 Chrome 扩展Postman发出请求时,它还能工作呢?
请求代码如下:
$.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);
});