2

I have a text file with all of the english nouns called 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.

EDIT: I would like a pure javascript way to do this, so no jquery or ajax.

4
  • What about using ajax. But this would be very unsecure. Commented Aug 29, 2015 at 15:09
  • possible duplicate of Get variable from text file in javascript? Commented Aug 29, 2015 at 15:21
  • @Daniel_L I wouldn't say it is a duplicate. They are somewhat similar, but this question has its own justification. Commented Aug 29, 2015 at 15:28
  • jQuery is written in pure JavaScript and AJAX (Asynchronous JavaScript And XML) is basically using the object XMLHttpRequest. That IS JavaScript. Almost everything you can do with jQuery, you can do also with plain (I'm not using the word pure, as it is wrong) JavaScript, jQuery makes the things much easier and simpler. There is no solution for your question, if you want to limit yourself for some unknown reasons only to "pure" JavaScript. Commented Aug 29, 2015 at 19:08

1 Answer 1

1

There is such possibility offered by the File API:

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

You'll find there also code examples for using the API.

This is however not yet supported by all browsers.

Sign up to request clarification or add additional context in comments.

3 Comments

This is a possible solution but i would like to find a way without either apis or anything else that isn't js.
You're also using the DOM, which is (not) as much JavaScript as the File API. How do you define pure JavaScript? The object window is also not pure JavaScript. If you run your script in a browser you're by force using APIs and objects it provides. You can use JavaScript on the command line, but that would require using node.js, which is probably also not "pure" JavaScript.
what about file already on webserver internally ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.