-2

how do I read a server side csv file on the load of my webpage. Here is the code that I am currently using, that runs on load of the webpage:

$.ajax({
    type: "GET",
    url: "titles.csv",
    dataType: "text",
    success: function(data) {
        processData(data);
    }
});

This code doesn't work giving me an error in the console of "No 'Access-Control-Allow-Origin' header is present on the requested resource." This doesn't make sense because the file is literally a local file to the server. I would appreciate some help. Thanks a bunch!

Jacob
  • 439
  • 6
  • 19
  • Are you loading the webpage from the server or from a local file? – Barmar Jun 28 '16 at 01:12
  • 1
    If you're loading a local file, see http://stackoverflow.com/questions/16683600/couldnt-ajax-local-file-from-local-html-page – Barmar Jun 28 '16 at 01:14
  • Nope guys, the webpage is being loaded from the server... the website is not being hosted by my computer. – Jacob Jun 28 '16 at 02:32
  • Then you shouldn't get this error. It only happens when a web page tries to use AJAX to access a URL in a different domain. – Barmar Jun 28 '16 at 02:42

1 Answers1

0

For your url value, use:

url: 'http://localhost/[DIRECTORY TO YOUR FILE]/titles.csv'
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • The webpage is being hosted not be me. The webpage is NOT being hosted client side on my computer. – Jacob Jun 28 '16 at 08:31