Javascript 使用java脚本代码在新页面重定向到用户
我试图将用户重定向到另一个页面,在完成一个过程之后,这个过程y由一个Api rest完成,但是为了完成这个过程,我从一个表单获取信息。问题是,当我尝试重定向到用户时,它不起作用,我不知道为什么 下面是我的JS代码:Javascript 使用java脚本代码在新页面重定向到用户,javascript,Javascript,我试图将用户重定向到另一个页面,在完成一个过程之后,这个过程y由一个Api rest完成,但是为了完成这个过程,我从一个表单获取信息。问题是,当我尝试重定向到用户时,它不起作用,我不知道为什么 下面是我的JS代码: document.addEventListener('DOMContentLoaded', () => { console.log('Document is ready'); const $form = document.querySelector('#comp
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');
}
})
})
重定向函数定义在哪里?。在JS中没有名为redirect的函数 试试下面一个
function redirect(to) { // what is the significant of to here?
window.location = "http://seth.com/dashboard.html?ftime=1";
}
重定向函数定义在哪里?。在JS中没有名为redirect的函数 试试下面一个
function redirect(to) { // what is the significant of to here?
window.location = "http://seth.com/dashboard.html?ftime=1";
}
您可以尝试以下方法:
function redirect(to)
window.location.href = "http://seth.com/dashboard.html?ftime=1";
}
您可以尝试以下方法:
function redirect(to)
window.location.href = "http://seth.com/dashboard.html?ftime=1";
}
这回答了你的问题吗?这回答了你的问题吗?