viren140290
viren140290

Reputation: 1

Read a CSV file stored on a web server using jQuery

I am trying this

$(document).ready(function() {
    $("button").click(function() {
        $.get('m.csv', function(result) {
            $("div").html(result);
        });
    });
});​

When the button is clicked it replaces the text on web page with the text in a csv file. It works fine for files stored on my local machine however when I replace the m.csv with a csv file stored on web server (for example, http://www.abc.com/a.csv) it doesn't work. How can I fix this?

Upvotes: 0

Views: 742

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382102

Your problem is that you're trying to read documents issued from another domain, an operation which is now prevented by Same origin policy. This can't work unless the server explicitly allows it by adding CORS headers.

If you can't ask the owners of the server to set the headers you need, your only solution would be to make those files appear as served by your server,

  • either by downloading them
  • or by using a proxy on your server.

Upvotes: 1

Related Questions