I have a CSV file hosted on a remote server. Is there a way for jQuery to consume that file so it can be converted to a jQuery array? Would I still be facing cross-site scripting problems?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll be running into restrictions imposed by the Same Origin Policy. In short, AJAX calls to a different domain are prohibited and will always (but for very very rare exceptions) fail, no matter what the content is.
You need to either use JSONP (mostly applicable to data returned by APIs) or proxy the request through your own server/domain.
Consuming the CSV itself is rather trivial:
Edit: Caution, as @echoback mentioned, I have missed the possibility of quoted values.
Luckily, there’s an awesome plugin that turns CSV into JSON. Just like that.