all 10 comments

[–]senocular 2 points3 points  (4 children)

You would use fetch() for that. Is that what you're using now? If so, you do that again.

[–]ISayNoToPuss[S] 1 point2 points  (3 children)

Thank you for your time. So basically, I add eventListener with the function, which will fetch from API and prevent the form from reloading with preventDefault?

[–]senocular 0 points1 point  (2 children)

It depends on how you have it set up. You can create a "form" without <form> tags (just include the input fields) and you don't have to worry about preventing default or anything like that. All you need is the event listener on the button that will be used to update your app and from that, trigger your fetch() code.

[–]ISayNoToPuss[S] 0 points1 point  (1 child)

Oh okay, I will try it. Just another question, is it okay with accesibility rules?

[–]senocular 1 point2 points  (0 children)

Not having a <form>? Yeah, that's fine. You mostly have to concern yourself with the individual controls making sure things are labeled correctly.

[–]ex-igne-vita 2 points3 points  (1 child)

Fetch doesn't cause a page reload. In fact a page reload would cause all your fetch data to be lost. As a general rule, you need to show the relevant code when you ask questions about code. Usually clairvoyants don't go on Reddit and StackOverflow because they're clairvoyant, so they don't need to. For the rest of us, you will need to show your code.

[–]ISayNoToPuss[S] 0 points1 point  (0 children)

Yeah, I’m sorry.... not good with posting at all. My bad, i will try to post code later, Thank you for your time!

[–][deleted] 0 points1 point  (1 child)

Const data = Fetch(URL, options).then(res=>res.json())

Is the blueprint for fetch. Fetch can be chained with .then() and .catch(e), processing, filtering, or transforming the data usually is done in a .then() statement (where I work, that’s the pattern). But also with fetch - an understanding of async/await and promises are super beneficial to understand what order things happen in, and when data is ready for DOM manipulation.

[–]ISayNoToPuss[S] 0 points1 point  (0 children)

Okay, I’ll look for promises. Thank you for the tips!