0

I'm trying to read in a simple text data file for a game. The file is in the same directory as the html and script files.

After a bit of research, I came to the conclusion that I have to use Fetch, which seemed weird for a local file, but I went ahead and tried it out, only to run into an error and then find out that apparently as of last year? fetching local files is no longer allowed due to some kind of security issue.

Using local files is evidently still possible in some capacity, as I can still use local image and sound files, and there's also the simple act of loading the javascript files themselves.

So what's the best way to go about doing this?

Reikken
  • 21
  • 1
  • 1
  • See this https://stackoverflow.com/q/18586921/1543677. – pkExec Jul 23 '20 at 04:55
  • It seems that the local file needs to be served using a server to be able to fetch it using "Fetch" API - Refer this - https://stackoverflow.com/questions/50007055/fetch-request-to-local-file-not-working. I tried accessing the html page from Apache server and it works fine. – vbrin27 Jul 23 '20 at 05:10
  • @Reikken To elaborate on my answer on the duplicate question... if you have control over the text file format, you can just turn it into JavaScript. That script could be something as simple as `window.data = { ... }`. If you don't have that sort of control, the only thing you can do is have the user drag the file in or use the file picker. – Brad Jul 23 '20 at 05:33
  • The file format is plain text (including punctuation, and etc) so I can't just make it javascript, and having the user manually select game data files to load while playing is definitely not gonna work. – Reikken Jul 23 '20 at 06:12

0 Answers0