html

How to read local text file into array list Javascript  #angularjs #reactjs

  • I have a small html file that is supposed to display the contents of a text file onto the screen.
  • The text (values.txt) is in the same file as the html file.
  • It appears that when it reads the contents it doesn’t get the values as they don’t appear in the alert.
  • here is the code

    what can I do in order to read a text file into a list / get this code snippet to work?

I have a small html file that is supposed to display the contents of a text file onto the screen. The text (values.txt) is in the same file as the html file. It appears that when it reads the contents it doesn’t get the values as they don’t appear in the alert.

@ng_real_ninja: How to read local text file into array list Javascript #angularjs #reactjs

I have a small html file that is supposed to display the contents of a text file onto the screen. The text (values.txt) is in the same file as the html file. It appears that when it reads the contents it doesn’t get the values as they don’t appear in the alert.

here is the code

what can I do in order to read a text file into a list / get this code snippet to work?

The main problem is that first of all you need to get the file for your function. Just passing the file’s name as argument is not enough.

Also is better to use an input of type file instead body with an onload attribute.

I’ve refactored your code in order to get it works.

1. Use this on your Html and delete body onload attribute.

I hope you may find this useful.

-field, but you may aswell try it with an ajax-call :

You might want to test it with Firefox, since Chromes security settings dont allow file-protocol requests.

You can read more about ajax calls here

html