re: How can I read a local JSON file in HTML/JavaScript? VIEW POST

re: You can use XHR to make a get request, check on google for more details

Umm, anything in specific I should look up, like a specific search phrase? Thanks!


@stas is referring to making AJAX requests, asynchronous server requests to load files. The modern browser solution is fetch.

This, however, requires a server.

ugh, that sucks....
why does almost EVERYTHING to do with file managing require a server?? There should be a non-server solution, that meets middle-ground for security, like only accessing html / css / js / json... etc... like it is everything, but why?? it makes it so much harder, especially for people that ONLY have access to file:// protocol ;-;
HTML / JS is so brutally strict.

Yeah it's definitely frustrating. There's a lot of historical baggage with file access from the browser though. We've had lots of dangerous stuff happen on the web when Flash and Java applets and such we'rye allowed to access the user's filesystem. They are actually working on it though: web.dev/native-file-system/. There's a ton of edge cases and hard security and API problems involved in it, so progress is slow because they really want to get it right. It's been worked on for 10+ years across several different specs. It's a very hard problem I guess.

code of conduct - report abuse