使用javascript读取本地文件 [英] Read a local file using javascript

查看:313
本文介绍了使用javascript读取本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取本地文件的内容,例如:

How do I get the contents of a local file, say:


/home/user/Wired/uploads/1.csv

/home/user/Wired/uploads/1.csv

变量 x 在javascript中?

in a variable x in javascript?

我可以使用filereader http:// www .w3.org / TR /文件上传/#DFN-的FileReader
如果是,那么怎么样?

Can I use the filereader http://www.w3.org/TR/file-upload/#dfn-filereader? If yes, then how?

推荐答案

你不能用严格的javascript做这个,但是你可以使用Web服务器作为用户和浏览器之间的中介。让用户异步上传文件(使用AJAX)。然后,Web服务器可以将纯文本值返回给AJAX调用。
这些内容可以随意使用。

You can't do this with strict javascript, but you can use the web server as an intermediate between the user and the browser. Have the user upload the file asynchronously (using AJAX). The web server could then return the plain-text value back to the AJAX call. The contents would then be free to use as you see fit.

如果不使用Flash / Silverlight / Java,这可能是您唯一的选择。

This is likely your only option without employing Flash/Silverlight/Java.

这篇关于使用javascript读取本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆