问题
I want to try and get data from an API but I am getting
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I cant change the content of API so I cant use JSONP
These are all I tried so far:
$.getJSON('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=keyhere&format=json&steamids=76561197970938759', function(data) {
console.log(data);
});
$.get("http://www.api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=keyhere&format=json&steamids=76561197970938759", function(data) {
console.log(data);
});
$.ajax({
type: 'GET',
url: 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=keyhere&format=json&steamids=76561197970938759',
dataType: "json",
success: function(data) {
console.log(data)
}
});
回答1:
As far as I know, if the server didn't enabled cross origin request in their headers, the browser will just not accept making an ajax call to it if you're on a different domain.
You could use your server to get the data and then send it to the client for example with CORS-Proxy or even use a website that does the proxying for you like CrossOrigin.me.
来源:https://stackoverflow.com/questions/40991377/access-steam-web-api-using-ajax-jquery