[Python] Why fetch() Doesn’t Reload the Page — And Why That Matters
Why fetch() Doesn’t Reload the Page — And Why That Matters
While working on my GTPS blog project, I came across an interesting behavior:
"Clicking a link or submitting a form reloads the page,
but sending a request withfetch()does not."
<a> and <form>: Traditional Behavior
When a user clicks a link or submits a form, the browser:
-
Sends an HTTP request (usually GET or POST)
-
Waits for the server’s response
-
Replaces the current page with whatever the server returns
This behavior is built into the browser — it’s automatic.
fetch(): JavaScript Takes Control
fetch() is part of the JavaScript Fetch API. It lets JavaScript send HTTP requests manually, without triggering navigation.
fetch('/add-game') .then(res => res.json()) .then(data => { console.log("Game added:", data); });
In this example:
-
The browser stays on the same page
-
The user never sees a reload
-
The UI is updated dynamically using JavaScript
Using fetch()
-
Seamless interactions
-
Partial page updates (without reloading)
-
Better user experience (no flash or reset)
Comments
Post a Comment