简体   繁体   中英

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.

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.

Try to add crossDomain: true and it should fix it .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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