Link to home
Start Free TrialLog in
Avatar of Tejlgaard
Tejlgaard

asked on

URL returns CSV text file - how to read file line by line?

Hello everyone, (my first post here)

I have an URL (http.//www.something.com/getCSV.asp?someid=xx) which returns a CSV file.

I need to code this in javascript, so I'm able to send off the http request and consume the returning file. Thereafter will I need to read the text file 'line-by-line' as i need to process the data.

Is there anyone that guide me in the right direction

Thanks in advance,

Tejlgaard
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Tejlgaard
Tejlgaard

ASKER

CEHJ - thanks for your comment - though I'm not sure what your points is.
I'm not sure what your points is.
You posted your question in the Java TA. It's not a Java question
Oh Sorry - thanks for the info - but probably just been easier to tell me that instead - I'll try to figure out how to change that
but probably just been easier to tell me that instead
Well i assumed, since you'd posted it here, you didn't understand the difference between Java and JavaScript

You need 'Request Attention'. Ask for JavaScripting zones
You could use jquerys get function to grab the csv and the jquery csv plugin to parse it.

As an example

$.get('http.//www.something.com/getCSV.asp?someid=xx', function(data) {
   var csvArray = $.csv()(data);
});

Open in new window


csvArray will contain its data. Then you could parse it with jquery's $.each function.

http://api.jquery.com/jQuery.get/
http://archive.plugins.jquery.com/project/csv
http://api.jquery.com/jQuery.each/
Looking back I don't think you can get jquery to grab data from external domain. You would need to create a wrapper.

If you have php on your webserver you could create a php script such as


csvWrapper.php
<?php
$homepage = file_get_contents('http.//www.something.com/getCSV.asp?someid=' . urlencode($_GET['someid']));
echo $homepage;
?>

Open in new window

This is a quite dirty script. You might want to handle some errors etc.

and then load it with .get

$.get('csvWrapper.php?someid=xxx', function(data) {
   var csvArray = $.csv()(data);
});
       

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tejlgaard
Tejlgaard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did not use any of the solutions - found alternative way to solve it