0

Today, i was doing a really cool project from frontendMentors, a planets website ! We have to do a 8 pages website (each page contains one planet details), we have the choice between writing every planet data directly in the HTML code, or, we can use a local data.JSON to manage it dynamically.

But, I got a problem:

I want to dynamically, with JS and the included data.JSON, write each planet page. So, i was like "Alright, I have to fetch data.JSON, and precise what planet to fetch, like :

fetch(`./data.json/${planetTitle}`)

But it obviously doesn't work like that. So, does anyone knows how to do it ? I'll give further informations like a screen of my JS + a screen of the data.JSON file.

JSON file; script.js;

Thx in advance !

There is the solution !

html trick script trick 1

VLAZ
  • 26,331
  • 9
  • 49
  • 67
remsB
  • 21
  • 6
  • Does this answer your question? [Fetching local JSON](https://stackoverflow.com/questions/49481934/fetching-local-json) – fynmnx Mar 17 '22 at 14:42
  • Is your site hosted on a webserver / localhost (emulated host)? – YourBrainEatsYou Mar 17 '22 at 14:57
  • IMHO you have 2 choices - at each page bring all planets and select one you need or separate json file into 8 with different names and bring one planet – Serge Mar 17 '22 at 15:18
  • `Alright, I have to fetch data.JSON, and precise what planet to fetch` only by using a scriptable server that serves the JSON can you pass it parameters, and have the server do the filtering. If you just have a "local JSON file" then no, you will need to load the whole JSON file and filter it in the client. – James Mar 17 '22 at 15:25
  • Thanks you really much guys ! You indirectly helped me to resolve my problem. I mean, you gave me an idea for filtering locally. I'll update my initial post with 2 more screens to show you how i did the trick ! – remsB Mar 18 '22 at 07:08

0 Answers0