[英]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.