大家好,我有以下代码,我正在尝试重定向到另一个代码,我正在使用 javascript html 来实现此目的,并且我是 html、javascript 和 php 的新手。它显示 test.php
,但当我单击按钮时,它不会重定向到 logout_success.php
。
<!DOCTYPE HTML>
<html>
<head>
<title>Sign-In</title> <link rel="stylesheet" type="text/css" href="style-sign.css">
</head>
<body id="body-color">
<div id="Sign-In">
<fieldset style="width:30%">
<legend>LOG-IN HERE</legend>
<form method="POST" action="connectivity.php">
User
<br>
<input type="text" name="user" size="40">
<br>
Password
<br>
<input type="password" name="pass" size="40"><br>
<input id="button" type="submit" name="submit" value="Log-In" onclick="document.location.href='http://localhost:8080/PortalWork/logout_success.php'">
</form>
</fieldset>
</div>
</body>
</html>
最佳答案
有两种方法。
(1)使用AJAX提交表单,并使用window.location.href重定向
$("#form1").submit(function(e){
e.preventDefault();
$.ajax({
url:'connectivity.php',
method:'POST',
success:function(rs){
if( rs == "success" )
window.location.href("logout_success.php");
},
error:function(){
alert("Error");
}
});
return false;
});
(2) 提交到服务器,并使用 header("Location:page.php") 进行重定向;
连接性.php
header("Location:logout_success.php");
关于javascript - html和javascript中从一个页面到另一个页面的重定向错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25663086/