-1

Currently I am trying to pull data from my steam inventory using the following link: http://steamcommunity.com/id/STEAMID/inventory/json/730/2. Using the link I can see the results in browser however when I actually try to pull the json with $.getJSON I simply cant figure out how to get it to work. Here is a simplified version of the code.

<script>
  $( document ).ready(function() {
    var items = {"rgIventory" : "4932985723947"};
    var url = "http://steamcommunity.com/id/STEAMIDHERE/inventory/json/730/2";
    $.getJSON(url, function(data) {
      document.getElementById("placeholder").innerHTML=data.rgInventory;
    });
    // document.getElementById("placeholder").innerHTML=items.rgIventory;
  });
</script>

This is just a simple project im trying to do, I want to eventually list everything in a nice table with the items according image. I just cant figure out how to pull in the JSON. Sorry for the stupid question I've just been working on this for a day now and can't wrap my head around it.

Thank you all in advance.

EDIT: Can someone post an example of what I need to do? Very confused.

mtcamesao
  • 43
  • 9
  • 1
    Is it being executed from the same origin, i.e. `http://steamcommunity.com`? – Drazen Bjelovuk Sep 16 '15 at 05:33
  • Are you sure that this API allows CORS requests? Do you have any errors in browser console? – unconnected Sep 16 '15 at 05:35
  • @unconnected I never even thought to look at the console, this is the wrrow I am getting. "XMLHttpRequest cannot load http://steamcommunity.com/id/STEAMIDHERE/inventory/json/730/2. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access." Is there a fix for this or and I just doing something wrong? – mtcamesao Sep 16 '15 at 05:38
  • possible duplicate of [Loading cross domain html page with jQuery AJAX](http://stackoverflow.com/questions/15005500/loading-cross-domain-html-page-with-jquery-ajax) – Phil Sep 16 '15 at 05:39
  • @unconnected basically what should I do to get around this? – mtcamesao Sep 16 '15 at 05:40
  • Unless the server supports JSONP, not much. – Drazen Bjelovuk Sep 16 '15 at 05:43
  • https://developer.valvesoftware.com/wiki/Steam_Web_API/Feedback#API_Considerations_for_Web_Developers – Phil Sep 16 '15 at 05:45
  • Error : {"success":false,"Error":"This profile is private."} – thangcao Sep 16 '15 at 05:59
  • I can't see any other way but to proxy requests through your server. So ajax requests local url, and server side requests steam and returns results back to the client. – unconnected Sep 16 '15 at 06:08
  • Is there another way that is possible maybe without JSON? – mtcamesao Sep 16 '15 at 06:32

1 Answers1

-1

Try using json. Example given below

$.ajax({
    type: 'GET',        
    url: '//steamcommunity.com/id/STEAMIDHERE/inventory/json/730/2',

    async: false,
    jsonp: "callback",
    jsonpCallback: 'someCallBackFunction',
    contentType: "application/json",
    dataType: 'jsonp',

    success: function (data) {
        console.log(data);
        //do your stuff
    },
    error: function (e) {
        console.log(e);            
    }
});
arpan desai
  • 889
  • 2
  • 13
  • 23