Home Events! Entrance Everyone Wiki Search Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
November 23, 2024 - @558.89 (what is this?)
Forum activity rating: Three Stars Posts: 32/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts    Start New Topic
News: :ozwomp: Reminder: Forum messages stay readable for years! Keep yours high quality! :ozwomp:

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  How to fetch values from a JSON file with JS?


« previous next »
Pages: [1] Print
Author Topic: How to fetch values from a JSON file with JS?  (Read 128 times)
asterhalloween
Casual Poster ⚓︎
*


the beauty of experiencing the world

⛺︎ My Room
SpaceHey: Friend Me!
iMood: mythicalwaters

View Profile WWW

First 1000 Members!Joined 2023!
« on: October 12, 2024 @826.04 »

Hello, everybody! I'm looking for a bit of help on how to do this thing because honestly I don't really know much about JavaScript (like almost nothing actually. dont let my yapping fool you) and as much messing around I've been doing I haven't been able to figure this out.

So, I want to create a Webring where people have little pixel bugs to help the ecosystem of their website. I'm using onionring as a base but for the widget I want to be able to automatically display the user's bug image as well as its name. A similar Webring I've seen is the jellyworld webring, which uses a JSON file to store the Webring members and their name, jelly, etc. and it puts it on the widget automatically by fetching the values based off of the url. It runs a bit different than the onionring system and so there are a few conflicting things with the system, but I don't particularly see why it wouldn't be possible to adapt onionring to do something similar, I just don't know how I would go about doing that.

I'm going to link the relevant files below, I haven't changed it much from the base template but thats because I removed all my attempts at getting it to work before because it kinda.. broke the whole thing :drat:

https://asterhalloween.neocities.org/buggyfriends/onionring-widget.js <- the thing that makes the widget and ideally would fetch from the json file
https://asterhalloween.neocities.org/buggyfriends/buggyfriends.json <- the json file
https://asterhalloween.neocities.org/buggyfriends/onionring-variables.js <- currently is what contains the urls. but i also yoinked the const so it gets the json
https://asterhalloween.neocities.org/buggyfriends/onionring-index.js <- I dont know if this will be useful at all for figuring this out but im linking it just incase ok
Logged

:4u: Love makes the world go round! :transport:
candycanearter07
Sr. Member ⚓︎
****


i like slimes

⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: candycanearter
Itch.io: My Games

View Profile WWW

Suck At Something September - Did It!uh oh! a pigeon got in!Artsy Candy CaneJoined 2024!
« Reply #1 on: October 15, 2024 @104.99 »

Looking it up, its actually really simple! fetch() has a special thing to parse JSON data to an object, and the fetch syntax is pretty easy. the only caveot is you need to define the function its in as an async function, or it will yell at you.

Code
async function funcNamewhatever() {
  let res = await fetch("yoursite.com/assets/whatever/file.json");
  if (!res.ok)
    { throw new Error(`HTTP Error while getting file: ${res.status}`); }

  let json = await res.json();
  return json;
}

also, the webring sounds super cute and i want to join :D
Logged

new to oldnet be nice




Pages: [1] Print 
« previous next »
 

Vaguely similar topics! (3)


Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021, Simple Machines | Terms and Policies Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi