access steam web API using AJAX Jquery

一世执手 提交于 2019-12-25 04:07:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!