[英]Login and redirect with ajax
当电子邮件和密码正确时,我想重定向到其他页面。 使用我的脚本,我可以使用户输入正确或错误的电子邮件和密码。 当它正确时,它会告诉“正确的电子邮件”,当它错误时,它会在“消息” div中告诉“错误的电子邮件或密码”。
现在,我想做的是,当消息为“正确的电子邮件”时,应将用户重定向到例如“ inside.php”。 我要添加什么脚本才能使其正常工作?
$(document).ready(function(){
$("form").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "login.php",
data: data
}).success(function(msg) {
$('#message').html(msg);
});
});
});
$(document).ready(function(){
$("form").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "login.php",
data: data
}).success(function(msg) {
window.location.href = 'desired_url' ;
});
});
});
成功时,使用window.location.href ='desired_url';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.