1
以下网址提供任何比赛的JSON格式的排名 https://www.codechef.com/api/rankings/OCT17 只是任何大赛代码CORS上Codechef的API(使用angularjs)
我想提出一个web应用程序,它会取这个API的替换OCT17和显示自定义的使用angularjs leaderboard.I尝试,但它是CORS错误
这是代码
`var app = angular.module('Ranklist', []);
app.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
console.log("cross origin allowed");
}
]);
app.controller('rank',function($scope,$http){
var uri = 'https://www.codechef.com/api/rankings/COPH2017?sortBy=rank&order=asc&page=1&itemsPerPage=25';
$scope.test = "test data";
console.log("love can hear")
$http.get(uri)
.then(function(response){
$scope.data = response.data;
});
});`
控制台表示铬这些2个错误
`Failed to load https://www.codechef.com/api/rankings/COPH2017?sortBy=rank&order=asc&page=1&itemsPerPage=25: The 'Access-Control-Allow-Origin' header has a value 'https://developers.codechef.com' that is not equal to the supplied origin. Origin 'http://127.0.0.1:58502' is therefore not allowed access.`
和
`angular.js:14525 Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"https://www.codechef.com/api/rankings/COPH2017?sortBy=rank&order=asc&page=1&itemsPerPage=25","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}`
有上无差错,而没有对铬 这会是个固定的,或者仅仅是一个服务器端的问题(或他们的偏好)
我也尝试$ http.jsonp()函数。