Question

Let's say I have a csv on a domain that I don't control at all and I want access to it on my page:

<script src="http://domainidontcontrol/blah.csv"></script>

Of course, this will throw a syntax error when the browser tries to parse the csv as it is not valid javascript. Is there any possible way to get access to the data in this csv from within the browser?

Was it helpful?

Solution

Look into CORS http://www.w3.org/TR/cors/ or JSON-P, if the other server has handlers set up. If those fail, you'll likely have to use a server-side proxy. Which wouldn't be too difficult, just make an AJAX request to your server, have your server fetch it, and return the results.

OTHER TIPS

Use a php/asp script on the server that will retrieve the csv file and return it to your page via ajax.

You should try to get the file using Ajax. For example with jQuery:

$.ajax({url:"http://domainidontcontrol/blah.csv", success:function(result){
  alert(result); //do something with the result
}});

That way now you can handle the contents of the file (the result) as you like since it will be a regular string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top