1

I'm trying to get data from a server with a jquery getJSON function. The server I'm trying to contact does not allow CORS so the connection needs to be whitelisted. My idea was to put this html and javascript file on a server and whitelist the server, but my colleauge says this will still not work because the javascript getJSON function is run in the browser. Which in his opinion would still generate a CORS error.

I'm totally new to javascript and server development so please enlighten me on this. How would I go about it?

I've already tried connecting through a proxy for the CORS connection.

$.getJSON(url, function(resp) {
 i = resp.total;
});

I want to get the value "total" but I'm recieving a CORS error.

lukas
  • 21
  • 1
  • Read up on how to create a proxy using stack your server is running. Making server to server requests is a fairly basic operation – charlietfl Apr 02 '19 at 12:50
  • Summary: you call your server-side method which makes a call to the third-party site. As long as your javascript and server-side code are sitting on the same server (base url) then it's not subject to CORS. Note: putting javascript on a server is not "server-side javascript" - so your colleague is correct there. It would be a case of running it server-side using a server-side technology such as php or c#. – freedomn-m Apr 02 '19 at 12:52
  • Please take a look: https://medium.com/netscape/hacking-it-out-when-cors-wont-let-you-be-great-35f6206cc646 – vladwoguer Apr 02 '19 at 12:53

0 Answers0