Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Read Text File Offline

Currently I use this code to read a txt file with words and perform some operations. However, this particular code requires the html to be deployed on a server. Is there any workaround where I can replace this code with something else to read the file without the need of a server?

var xhr = new XMLHttpRequest(); 
xhr.open( "GET", "dictionary.txt", false );
xhr.send( null );
var words= xhr.responseText.split(",");
like image 739
Kerry Avatar asked Sep 21 '25 04:09

Kerry


1 Answers

It is NOT possible to call Ajax outside your server domain (except you use scriptagproxy, that too requires you to have some server side configuration). So, in short, you CANNOT read files on your local computer using Ajax calls.

You might like this article.

The file selection can be made either by input or drag-and-drop (not otherwise). Please see: this

like image 176
hrishikeshp19 Avatar answered Sep 22 '25 18:09

hrishikeshp19