1

I'm trying to redirect a user to another page, after of complete a process, the process y done by an Api rest, but for making that process, I'm getting information from a form. the problem is that when I try to redirect to the user, it no works, and I'm not sure why.

My JS code is the next:

document.addEventListener('DOMContentLoaded', () => {
    console.log('Document is ready');
    const $form = document.querySelector('#completedetails');
    const $inputName = document.querySelector('#name');
    const $inputPassword = document.querySelector('#password');
    const $inputCompany = document.querySelector('#company');
    const $btn_completedetails = document.querySelector('#btn-completedetails');

    const url = "http://localhost:3000/register/";

    $form.addEventListener('submit', async (e) => {
        e.preventDefault();
        let name = $inputName.value;
        let password = $inputPassword.value;
        let company = $inputCompany.value;
        const response = await fetch(`${url}${company}${name}${password}`, { method: 'POST' });
        const result = await response.json();
        function redirect(to) { 
            redirect('http://seth.com/dashboard.html?ftime=1');
         }

    })


})
  • Does this answer your question? [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – kmoser Aug 19 '20 at 05:48

2 Answers2

1

You can try this:

function redirect(to) 
  window.location.href = "http://seth.com/dashboard.html?ftime=1";
}
Arijit Jana
  • 220
  • 1
  • 4
0

Where is redirect function definition?. In JS there is no function named as redirect.

Try below one

 function redirect(to) { // what is the significant of to here?
  window.location = "http://seth.com/dashboard.html?ftime=1";
}
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44