I'm struggling with a problem that seems easy. I have a json data that is stored as a plain text file on some server and I need to load it in javascript. I am getting error
XMLHttpRequest cannot load http://www.cgarea.com/ary_telemetry/messages.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
I was reading about CORS and testing different solutions with no success. If the destination URL was a PHP script I could set a header('Access-Control-Allow-Origin: *') but it's just a text file. How can I load this? Do I need to create a tiny PHP script to just return file content?
I put a minimal code on http://jsfiddle.net/rt6jj5tv/6/
Any tips appreciated, thanks.
JS code:
function GetMessages() { //$.getJSON("http://www.cgarea.com/messages.json", GetMessagesCB); $.ajax({ type: 'GET', url: "http://www.cgarea.com/messages.json", dataType: "text/plain", success: GetMessagesCB }); } function GetMessagesCB(data) { console.debug(data); var ui = document.getElementById("Message"); ui.innerHTML = data; } GetMessages();