【发布时间】:2017-12-15 20:27:32
【问题描述】:
我收到了错误
Failed to load https://store-cmr1f5oakh.mybigcommerce.com/api/v2/products: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://tim-yma5.mybigcommerce.com' is therefore not allowed access. The response had HTTP status code 401.
我用ajax调用api
$.ajax({
url: "https://url/api/v2/products",
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic " + btoa("username" + ":" + "token"));
},
type: 'GET',
dataType: 'json',
success: function(data){
console.log("api_success");
}
});
如何避免No 'Access-Control-Allow-Origin'?
【问题讨论】:
标签: ajax api bigcommerce