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()函數。