简体   繁体   English

使用纯JavaScript从文本文件读取数据

[英]Reading data from a text file with pure javascript

I have a text file with all of the english nouns called words.txt . 我有一个文本文件,其中包含所有名为words.txt的英语名词。 And my goal is to look for a word given by the user in this file. 我的目标是在该文件中查找用户给出的单词。 But since I'm new to javascript, I was hoping to find a way with which, in pure javascript, I can save this file into a variable in which i can later look for the word that has been input. 但是,由于我不熟悉javascript,所以我希望找到一种方法,可以用纯javascript将文件保存到变量中,以便以后可以查找已输入的单词。

EDIT: I would like a pure javascript way to do this, so no jquery or ajax. 编辑:我想要一个纯JavaScript的方式来做到这一点,所以没有jquery或ajax。

There is such possibility offered by the File API: File API提供了以下可能性:

http://www.w3.org/TR/file-upload/ http://www.w3.org/TR/file-upload/

You'll find there also code examples for using the API. 您还会找到使用API​​的代码示例。

This is however not yet supported by all browsers. 但是,并非所有浏览器都支持此功能。

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

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