注册成功后,我的用户将被重定向到主页:
echo
"<script type=\"text/javascript\">
window.location.href='../index.php';
</script>";
我是否需要按照
进行操作exit();
或正在重定向用户?
[编辑]帮助解决如何在同一个php文件中使用die()/ exit()和javascript
jQuery的:
$(document).ready(function() {
$("form").submit(function(event) {
event.preventDefault();
var username = $("#register-username").val();
var email = $("#register-email").val();
var password = $("#register-password").val();
var confirmPassword = $("#register-confirm-password").val();
var submit = $("#register-submit").val();
$(".form-message").load("../shared/_registerAccount.php", {
username: username,
email: email,
password: password,
confirmPassword: confirmPassword,
submit: submit
});
});
});
PHP脚本结束(成功路径):
else
{
$errorEmpty = $errorUsername = $errorEmail = $errorPassword = $errorConfirmPassword = false;
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($statement, "sss", $username, $email, $hashedPassword);
mysqli_stmt_execute($statement);
session_start();
$_SESSION['register-success'] = 'You have successfully registered! Please verify your email before logging in.';
$registrationSuccessful = true;
die('<script type="text/javascript">location.assign("../index.php")</script><a href="../index.php">Home</a>');
}
jQuery遵循同一文件中的PHP脚本:
<script type="text/javascript">
var registrationSuccessful = "<?php echo $registrationSuccessful; ?>";
if (registrationSuccessful)
{
$("#register-username, #register-email, #register-password,
#register-confirm-password").val("");
}
</script>
答案 0 :(得分:2)
您假设 JavaScript 将始终在所有用户浏览器上可用(或启用)。我严重建议使用原生的Sub CATMain()
Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = drawingDocument1.Selection
selection1.Search "CATDrwSearch.DrwCallout,all"
selection1.Search "Drafting.Text,sel"
Dim i As Integer
For i = 1 To selection1.Count
MsgBox selection1.Item(i).Value.text
Next
End Sub
PHP 功能:
header
或者,如果不可能(无论出于何种原因),如果 JavaScript 未启用,则至少为用户提供一种替代方式:
die(header("Location: ../index.php"));
答案 1 :(得分:1)
我建议exit()
,如果重定向后还有其他代码。如果您没有任何代码,那么您就不必这样做了。
如果您在exit
之前使用任何提醒,请使用refresh
保留页面,否则会在几分之一的时间内提醒您。