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
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
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
ASKER
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 insteadWell 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
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/
As an example
$.get('http.//www.something.com/getCSV.asp?someid=xx', function(data) {
var csvArray = $.csv()(data);
});
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
and then load it with .get
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;
?>
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);
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Did not use any of the solutions - found alternative way to solve it
http://technojeeves.com/joomla/index.php/free/127-javascript-is-not-java