我正在尝试向' https://connect.squareup.com/v2/locations'使用angularjs,呼叫失败,说403 FORBIDDEN。
以下是代码示例:
var url = 'https://connect.squareup.com/v2/locations';
var config = {
headers: {
'Authorization': 'Bearer sandbox-sq0atb-JJGltCa375qzAyoQbjPgmg',
'Accept': 'application/json',
"X-Testing": "testing"
}
};
$http.get(url, config)
.then(
function (response) {
console.dir(response);
},
function (response) {
console.log("failed" + response)
}
);
我做了上述样本的小提琴。任何帮助表示赞赏。
答案 0 :(得分:1)
您是否看到此错误:XMLHttpRequest cannot load https://connect.squareup.com/v2/locations. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
?这意味着您无法通过前端Javascript(如AngularJS)访问API。您需要使用其他实现,如Node.js,PHP等。