[英]How can I redirect to login page after registration in this code
every help me :(((. here is link to my code https://github.com/tranluongtiensi/registration_system每一个帮助我:(((。这里是我的代码的链接https://github.com/tranluongtiensi/registration_system
I want to redirect the user to login page after registration, I have tried many ways but it doesn't work.我想在注册后将用户重定向到登录页面,我尝试了很多方法但它不起作用。 thank everyone very much
非常感谢大家
You can just use the window.location.href
when you submit your signup form.提交注册表单时,您可以只使用
window.location.href
。 So your code for registerUser(...)
would look something like this.所以你的
registerUser(...)
代码看起来像这样。
async function registerUser(event){
event.preventDefault()
const username = document.getElementById('user').value
const password = document.getElementById('password').value
const password_confirmation = document.getElementById('password_confirmation').value
const phone = document.getElementById('tel').value
const result = await fetch('/register',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username,
password,
password_confirmation,
phone
})
}).then((res) => res.json())
if (result.status === 'ok') {
alert('success');
// on a successful signup, redirect user to the login page
window.location.href = 'LINK_TO_SIGNIN_PAGE'; // exp. http://localhost/signin.html
}else {
alert (result.error)
}
}
Give it a go!搏一搏!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.