简体   繁体   English

如何使用在HTML中返回csv的网址? 换句话说,如何在我的网页中显示该csv文件中的数据?

[英]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 我有这个网址-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. 这个网址传回一个csv档案。我想使用这个网址来列印网页中存在的资料。 now the problem is that i dont know how to get the data into the html code.does it need javascript? 现在的问题是我不知道如何将数据输入html代码。它需要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)? 我想知道我是否应该在html中使用<url>标记。我不认为这行得通。或者还有其他方法(如果可能的话)吗?

note: i want to use html,javascript,java(if required) 注意:我想使用html,javascript,java(如果需要)

PS: to be more precise this is a yahoo stock api. PS:更准确地说,这是雅虎股票api。

any help is appreciated. 任何帮助表示赞赏。

PS: doing this using XML will also be very helpful. PS:使用XML进行此操作也将非常有帮助。 because there is another api url that returns XML data. 因为还有另一个返回XML数据的api url。 (google stock api) eg http://www.google.com/ig/api?stock=grasim (google stock api),例如http://www.google.com/ig/api?stock=grasim

You want to get some framework such as JQuery and form a request to this url. 您想获得诸如JQuery之类的框架并形成对此URL的请求。

On the success code of the request you want to Parse the output using some CSV Reader. 要在请求的成功代码上,您要使用某些CSV阅读器解析输出。

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. http://archive.plugins.jquery.com/project/csv可能适合您的需求,然后您将要从该点开始将阵列吐出到页面中。

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. 我在这里创建了一个示例,但遇到了一些XSS问题,但是如果您在堆栈中询问或检查现有问题,则应该找到最终的解决方案。

http://jsfiddle.net/gWBBE/ 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 http://www.dhtmlx.com/docs/products/dhtmlxDataView/samples/03_loading/01_xml.html

You could also start using Yahoo's own Javascript library . 您也可以开始使用Yahoo自己的Javascript库

It will provide you with YUI IO (ajax) posibilities to fetch data. 它将为您提供YUI IO(ajax)可能性来获取数据。 Here you can find a few simple examples on how to use YUI IO on your page to get other sites' data. 在这里,您可以找到一些有关如何在页面上使用YUI IO来获取其他网站数据的简单示例。

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. 现在,当您执行此操作时,还可以使用YUI数据表在网页中显示该数据,而不必产生自己的html,YQL(雅虎查询语言),数据源和许多其他有用的东西。

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. 只需向该网址发送httprequest并使用响应即可。 Missed the callback on the initial answer, readystate 4 signals data transfer completion. 缺少初始答案的回调,readystate 4表示数据传输完成。

Then in plain js it looks sth like this: 然后在普通的js中看起来像这样:

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 该链接可能会有所帮助: 用于解析CSV数据的Javascript代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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