Avatar ·

How to refresh (reload) a page using JavaScript?

Hello everyone! I'm a beginner in JavaScript and I've encountered this task: after the user clicks the "Submit" button in a form, I need the page to automatically refresh to reset all fields and show the latest data from the server. I tried to do this using window.location = window.location.href, but for some reason the page just hangs, and sometimes it throws a "too many redirects" error. Here's my code: ```javascript document.getElementById('myForm').addEventListener('submit', function(event) { event.preventDefault(); // ... here I send data via fetch or XMLHttpRequest ... window.location = window.location.href; // trying to refresh the page }); ``` Please tell me what is the correct way to reload a page in JavaScript? Maybe there is