使用AJAX Jquery访问Steam Web API [英] access steam web API using AJAX Jquery

查看:183
本文介绍了使用AJAX Jquery访问Steam Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试从API获取数据,但是我正在获得

I want to try and get data from an API but I am getting

所请求的资源上没有"Access-Control-Allow-Origin"标头.因此,不允许访问原始空".

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

我无法更改API的内容,因此无法使用JSONP

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)
  }


});

推荐答案

据我所知,如果服务器未在标头中启用跨源请求,浏览器将不会接受对它的Ajax调用您在其他域中.

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.

您可以使用服务器获取数据,然后将其发送到客户端,例如,使用 CORS-代理,甚至使用像您这样的网站进行代理,例如 CrossOrigin.me .

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.

这篇关于使用AJAX Jquery访问Steam Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆