0

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.

karel
  • 5,489
  • 46
  • 45
  • 50
  • Possible duplicate of [Why does my JavaScript code get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-get-a-no-access-control-allow-origin-header-is-pr) – Mason Stewart Aug 11 '19 at 19:52

1 Answers1

0

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);
      }
  });
Noob
  • 2,247
  • 4
  • 20
  • 31