0

I've got a problem and it's the same problem as here. But i don't get it what he ment with

What you need to do is introduce a middle-ware, so have your back-end server to make a request against steamcommunity.com and return the same response, and make the ajax call against you're server. This will work, your back-end is sending the request, and as it is not a browser request, the response will land, than your ajax call will be able to get the response as well since it is issued against the same domain.

The Error i get is "Access-Control-Allow-Origin" and here he says why i get this so im asking how to "fix" this.

How can my back-end server make a request against steamcommunity.com and a ajax call against my server(Xampp Localhost)? So what exactly is the solution? Is there somewhere a documentation or tutorial? Can someone make a code example (or tell me where I can code this because i assume that according to the answer you can't request the json with the browser(within the websitecode)) because else I won't get it.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
JDev
  • 124
  • 1
  • 9

1 Answers1

2

How can my back-end server make a request against steamcommunity.com and a ajax call against my server(Xampp Localhost)?

It can't, but that isn't what the material you quoted says you should do.

The Ajax call is made by the browser not by your server.

What is says is this:

  1. Your JavaScript makes an HTTP request to your server (which is the same server that served up the HTML document the JS is running in, which means that the HTTP request is being made to the Same Origin).
  2. Your server makes an HTTP request to Steam's server
  3. Steam's server makes an HTTP response to your server
  4. Your server processes that response and uses the data from it to make an HTTP response back to your JavaScript running in the browser.
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • If i make a HTTP request it gives me the error "Access-Control-Allow-Origin". So how can i fix this? JasonP won't work according to this :http://stackoverflow.com/questions/26982749/jquery-json-error-when-i-want-to-get-json-from-steam-market. PS: I edited the question a bit... – JDev Nov 12 '15 at 19:54
  • @BloodWoork — It will only do that if you make the request to a different origin. To fix it you do what I just said in this answer. – Quentin Nov 12 '15 at 19:56
  • Ok, well because i'm not that expirienced i don't know how to make a http request to the server... How to programm, what u said? Sorry if that is totally stupid... – JDev Nov 12 '15 at 19:59
  • [How to make an Ajax request](https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) – Quentin Nov 12 '15 at 20:01
  • [How to send a GET request from PHP](http://stackoverflow.com/questions/959063/how-to-send-a-get-request-from-php) – Quentin Nov 12 '15 at 20:01
  • Isn't that a ajax request?:`code` function jPrice(httpToJson) { $.getJSON(httpToJson, function(data) { return data.median_price; }); } – JDev Nov 12 '15 at 20:06
  • Yes. Great. Now make it to the right URL (i.e. one on your own server as step 1 of this answer says). – Quentin Nov 12 '15 at 20:08
  • Ok where to on my server? (at the moment localhost but i do have a website) jPrice('localhost') but on my localhost there is no json to get... – JDev Nov 12 '15 at 20:14
  • like this? `code``code` ? lead it to a php file? – JDev Nov 12 '15 at 20:23
  • Thank you so much! I get it! – JDev Nov 12 '15 at 20:32