• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

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
0
Tejlgaard
Asked:
Tejlgaard
  • 4
  • 3
  • 2
1 Solution
 
CEHJCommented:
0
 
TejlgaardAuthor Commented:
CEHJ - thanks for your comment - though I'm not sure what your points is.
0
 
CEHJCommented:
I'm not sure what your points is.
You posted your question in the Java TA. It's not a Java question
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TejlgaardAuthor Commented:
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
0
 
CEHJCommented:
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
0
 
Chris SandriniSenior System EngineerCommented:
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/
0
 
Chris SandriniSenior System EngineerCommented:
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

0
 
TejlgaardAuthor Commented:
Sorry for the late response - thanks to all that answered
0
 
TejlgaardAuthor Commented:
Did not use any of the solutions - found alternative way to solve it
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now