How can I use JavaScript to load a JSON file from my desktop? or What's the best way to load a JSON f

14 Replies, 1332 Views

CORS errors are the worst, right? For javascript load json file from desktop, you could also try Electron if you’re building a desktop app. It has full filesystem access, so no CORS issues.

Otherwise, the `fetch()` workaround is either:
1. Use a local server (best practice).
2. Use `XMLHttpRequest` with `file://` (not reliable).

Here’s a quick local server setup:
```bash
python -m http.server 8000
```
Then hit `http://localhost:8000/data.json` in your fetch call.

Messages In This Thread



Users browsing this thread: 1 Guest(s)