0

I am trying my following code to get Steam Inventory using JSONP but it give me following error:

Uncaught SyntaxError: Unexpected token :

$.ajax({
    url: "http://steamcommunity.com/profiles/76561198383144224/inventory/json/730/2",
    dataType: "jsonp",
    jsonp: 'jsonp',
    jsonpCallback: "callback",
    success: function(response) {
        alert("Success")
        console.log(response)
    },
    error: function(response) {
        alert("Error" + response.status)
    }
});

Is there any error or need to change my code?

Demo

Luka Čelebić
  • 1,083
  • 11
  • 21
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
  • The data at that endpoint is JSON, not JSONP. – Andy Sep 28 '17 at 10:04
  • 1
    Firstly, the response is JSON, not JSONP. They are not interchangeable - hence the syntax error. Secondly, when you correct the AJAX call to expect a JSON response you get the error `No Access Control header...` as the domain you're calling does not include CORS headers in the response - which is presumably why you tried using JSONP in the first place. Long story short, you cannot call this domain from JS code as you will be blocked by the Same Origin Policy – Rory McCrossan Sep 28 '17 at 10:05
  • When I called with Ajax request then I got error **No Access Control header** – Sadikhasan Sep 28 '17 at 10:07
  • Exactly my point. – Rory McCrossan Sep 28 '17 at 10:07
  • What I have to do @RoryMcCrossan – Sadikhasan Sep 28 '17 at 10:07
  • Make the call server side. JS is blocked. See the question I marked as duplicate for more informartion – Rory McCrossan Sep 28 '17 at 10:07
  • Or you can change your server configuration to allow-origin – Miguel Coder Sep 28 '17 at 10:08
  • 1
    @MiguelCabrera It's obviously not his server, unless the OP Is GabeN :D – Rory McCrossan Sep 28 '17 at 10:08
  • When I called from server side then it block my request. Because within minute atleast 100 hiting. – Sadikhasan Sep 28 '17 at 10:09
  • Or you could make a PhantomJS instance return the data to node that way. ;) – Miguel Coder Sep 28 '17 at 10:09
  • 1
    @Sadikhasan do you mean you're calling the endpoint 100 times in quick succession? If so I'm not surprised they blocked you. – Rory McCrossan Sep 28 '17 at 10:10
  • I created website in which different different user can hit that api. Not single user multiple user hit that url with different different id. – Sadikhasan Sep 28 '17 at 10:11
  • @Sadikhasan Make a phantomJS application that sends the data to your backend and back to your front-end. Then you can execute javascript from the same origin because you will be running a headless browser. – Miguel Coder Sep 28 '17 at 10:18

0 Answers0