CORS is a setting that must be modified on the server. It allows resources on a webpage to be requested by an external domain. Simply changing your code on the client will not change the functionality of CORS.
The reason you can access a page from within a "script" tag, is because tags are treated differently than all other data for cross origin requests. In the old days, you could "hack" CORS onto your system using JSONP which stores JSON data inside of HTML tags.
To enable CORS in Apache:
First find your httpd.conf by typing
ps -ef | grep apache
Which will give you the location of Apache. Once you have found that type:
<apache-location> -V
Which will return the exact location of your httpd.conf like such:
-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"
Now you need to go to httpd.conf and type "/" to search for <directory>
. Once you find the tag, right after it type:
Header set Access-Control-Allow-Origin "*"
Save the file and confirm the syntax is correct by running:
apachectl -t
If that checks out, run the graceful restart command:
apachectl -k graceful
Once the server restarts, your files should now be accessible via external scripts.
If you where not able to save the config due to an error, try exiting your editor and typing:
sudo chmod 755 httpd.conf
This gives the owner full access to the configuration file but everyone else can only read an execute it (http://en.wikipedia.org/wiki/Chmod).
To test these changes, on an external server create a new index.html file and load it up with the following:
<!doctype html>
<html>
<head>
<title>TEST</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<!-- Insert Scripts & CSS Here -->
<link rel="stylesheet" type="text/css" href="http://d1e24pw9mnwsl8.cloudfront.net/c/bootstrap/css/bootstrap.min.css">
</head>
<body>
<script>
jQuery.get('yourwebsite.com/file.csv', function(data) {
document.write(data);
});
</script>
</body>
</html>
The resulting output should mirror the live data feed at yourwebsite.com/file.csv
If loading up that html page shows no ouput, press f12 on firefox to open the developer's console. Most likely you will see an error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at yourwebsite.com/file.csv. This can be fixed by moving the resource to the same domain or enabling CORS.
This means either a) your httpd.conf was not configured correctly/did not save, or b) you forgot to restart the web server.