我正在使用sphere-engine api .
我想发送一个GET请求,以获得他们拥有的编译器列表 .
根据他们的文档..我可以通过这样做获得列表 .
请求示例(CURL)
curl -X GET -H 'Content-Type: application/json' "http://db4262da.problems.sphere-engine.com/api/v3/compilers?access_token=xxxx"
现在我想用AJAX REQUEST来做 .
这是我的代码..
$.ajax({
type: "GET",
url: "http://db4262da.problems.sphere-engine.com/api/v3/compilers?access_token=xxxx",
contentType: "application/json",
success: function(result, data){
// var obj = JSON.parse(result);
// $scope.submitId = obj.id;
// console.log(obj.id);
},
});
问题是 . 我总是得到这个错误
XMLHttpRequest无法加载http://db4262da.problems.sphere-engine.com/api/v3/compilers?access_token=xxxx . 对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头 . 因此,不允许来源“http://heuricode.dev”访问 . 响应具有HTTP状态代码405 .
1 回答
您不应该使用Javascript代码级别的Sphere Engine API . 请注意,您的
access_token
将公开 . 因此,每个人都能够看到它并使用它 .您应该从应用程序的后端与Sphere Engine API进行通信 . 如果要对Sphere Engine API进行异步调用,则应构建自己的层 . 最后,异步调用可能如下所示: