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

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

问题描述

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

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

请求的资源上不存在Access-Control-Allow-Origin"标头.因此,不允许访问原点 'null'.

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天全站免登陆