简体   繁体   English

如何使用带有 Steam Web API 的 JSON 格式的 javascript-jquery 获取所有 Steam 应用

[英]How to get all steamapps using javascript-jquery in JSON format with Steam web API

I'm trying to fetch all the Steam apps using the Steam API.我正在尝试使用 Steam API 获取所有 Steam 应用。

JavaScript: JavaScript:

var previewUrl = 
"http://api.steampowered.com/ISteamApps/GetAppList/v0002/?key=mysteamkey&format=json";
  $.ajax({
      type: 'GET',
      url: previewUrl,
      success: function(data) {
        console.log(data);
      },
      error: function(e) {
         console.log(e.message);
      }
  });

But it gets me this error on console:但它在控制台上给我这个错误:

Access to XMLHttpRequest at 'http://api.steampowered.com/ISteamApps/GetAppList/v2/?key=mysteamkey&format=json' from origin 'http://localhost:5000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. CORS 策略已阻止从源“http://localhost:5000”访问“http://api.steampowered.com/ISteamApps/GetAppList/v2/?key=mysteamkey&format=json”上的 XMLHttpRequest:无“访问” Control-Allow-Origin' 标头存在于请求的资源上。

Try to add crossDomain: true and it should fix it .尝试添加crossDomain: true ,它应该修复它。

var previewUrl = 
"http://api.steampowered.com/ISteamApps/GetAppList/v0002/?key=mysteamkey&format=json";
  $.ajax({
      type: 'GET',
      crossDomain:true,
      url: previewUrl,
      success: function(data) {
        console.log(data);
      },
      error: function(e) {
         console.log(e.message);
      }
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM