简体   繁体   中英

How to use a url which returns a csv in HTML? in other words how to display the data from that csv file in my webpage?

let me be real specific. I have this URL- http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=snd1l1yr

this url returns a csv file.i want to use this url to print the data present in it in my webpage. now the problem is that i dont know how to get the data into the html code.does it need javascript?

i want to know if i should use the <url> tag in html.i dont think that will work.or is there any other way to do it (if it is possible)?

note: i want to use html,javascript,java(if required)

PS: to be more precise this is a yahoo stock api.

any help is appreciated.

PS: doing this using XML will also be very helpful. because there is another api url that returns XML data. (google stock api) eg http://www.google.com/ig/api?stock=grasim

You want to get some framework such as JQuery and form a request to this url.

On the success code of the request you want to Parse the output using some CSV Reader.

http://archive.plugins.jquery.com/project/csv May suit your needs and then all you do from that point is spit out the array to the page.

Sorry I cant be more precise but I hope this points you in the right direction. I'm sure others will give much better answers.

I have created a sample here I got some XSS problems but If you ask around stack or check existing questions you should find the final solution.

http://jsfiddle.net/gWBBE/

And also although this is for University people at stack do this to help each-other not to do other peoples homework.

<object data="quotes.txt"></object>

you can use object tag to embedded any file or webpage to display into any webpage.

And also have look by using framework

http://www.dhtmlx.com/docs/products/dhtmlxDataView/samples/03_loading/01_xml.html

You could also start using Yahoo's own Javascript library .

It will provide you with YUI IO (ajax) posibilities to fetch data. Here you can find a few simple examples on how to use YUI IO on your page to get other sites' data.

Now, when you do that, you can also use YUI datatable to show that data in the web page without having to produce your own html, YQL (yahoo query language), datasources, and a lot of other useful things.

Now, your question seems a bit specific, but it covers a lot, so the answers are such too.

I think it all boils down to requesting the data and then parsing and displaying it.

Just send a httprequest to that url and work with the response. Missed the callback on the initial answer, readystate 4 signals data transfer completion.

Then in plain js it looks sth like this:

function httpGet(url)
{
 var xmlHttp = null;

 xmlHttp = new XMLHttpRequest();
 xmlHttp.open( "GET", url, false );
 xmlHttp.onreadystatechange = callbackFunction;
 xmlHttp.send( null );
}

function callbackFunction()
{
 if (xmlHttp.readyState != 4)
 return;

 var result = xmlHttp.responseText;
}

At least then u can parse the response and work with it as you like. This link might be helpful: Javascript code to parse CSV data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM