Fetch API not supported?

I am trying to retrieve data from Jotform tables via the API. However, I am getting the following error message:
"Error parsing hooks ReferenceError: Can’t find variable: fetch on line 5
"
After some research, it seems this indicates that the Fetch API is not supported. Is there an alternative method that does work?

sounds like you’re trying to use the hooks.js file to fetch data?

If so, this is not supported.

If you need to fetch data that will be displayed on the site, then you need to use a template (if you’re creating a dev component then you could create a templates/script.js file) and place the javascript code in there.

If the javascript needs to be placed in a certain area of the page you can use a @portal for that.

See the portal docs for more info: Portal | RapidWeaver Elements Docs

Hope that helps!?

1 Like

Thanks @bon for your support. I tried the Portal solution and that works fine :tada:

2 Likes

Loads much faster than google sheets.

Nice! I’m not sure exactly what you’re building, but if you’re fetching data from an external source, you could look at caching it in local storage on the user’s browser - and just wait / poll for updates via js.

Would improve the initial page load, and make the page dynamically update as the data changes - just an idea if you’re looking for “stretch goals” :smiley:

I have a website for a supporters’ club for people with disabilities, focused on a Belgian top-tier football club (KRC Genk). I ensure they can register and pay through Jotform. For the management, there’s a restricted page where they can view an overview, such as the number of wheelchairs needed on the bus, how many people have a companion, and so on.

In the current site, the Jotform data is stored in a Google Sheet file, where calculations are also performed. I then retrieve the data using a Stack. However, on the new site, I want to fetch the data directly from Jotform using a custom component, and that seems to be working well. The possibilities with Elements in that regard are almost limitless.

2 Likes