I have a node ('test.js') script that outputs JSON data to the screen. I compile and run it, and when I open the site in my browser http://localhost:3000/myWorkspace/Projects/MW-KD/ I can see the json data {'kills':22,'deaths':11,'map':'someMap','kdRatio':2.........} on the screen.
Now I want to read this data from another javascript file using $.ajax. I tried everything btw. ($.get(), $.post(), $.getJSON, fetch() etc)
The code I use is:
let settings = {
'cache': false,
'dataType': "json",
'async': true,
'crossDomain': true,
'url": "http://localhost:3000/myWorkspace/Projects/MW-KD/',
"method": "GET",
"headers": {
"accept": "application/json",
"Access-Control-Allow-Origin":"*"
}
}
let testJSON = $.ajax(settings)
testJSON.done((data) => console.log(data))
I tried like every single combination people use but still I get a f.... CORS error.
Access to XMLHttpRequest at 'http://localhost:3000/myWorkspace/Projects/MW-KD/?_=1587570791195' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This CORS error is haunting me for days now. I got em when using Activisions API. I got 'em when using javascript. Then I thought I could use a 3rd party API using NODE. So I installed and looked up the basics. I got the API to run and return me results form Activisions API.
AND NOW I CANT READ THE DATA ON MY OWN MACHINE. I'm about to lose my mind.