我有下面的PHP if/else语句-我如何告诉它返回login.PHP并运行jQuery函数?
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
$_SESSION['SESS_LOGIN'] = $member['login'];
session_write_close();
header("location: ../index.php");
exit();
}else {
$error = true;
// go back to login.php and run jQuery function
}
}else {
die("Query failed");
// // or go back to login.php and run different jQuery function
}
您可以使用:
header('Location: login.php?message=query_failed');
或
header('Location: login.php?message=login_failed');
以及在login.php
上的javascript tags
:
您可以将php
用于:
<?php if($_GET['message'] == 'query_failed'): ?>
jquery_query_failed_function();
<?php elseif($_GET['message'] == 'login_failed'): ?>
jquery_login_failed_function();
<?php endif; ?>
所以继续你的else
声明:它应该是:
继续你的其他声明:
else {
$error = true;
header('Location: login.php?message=login_failed');
}
}else {
header('Location: login.php?message=query_failed');
die("Query failed");
// // or go back to login.php and run different jQuery function
}
header("Location: ../login.php?error_code=1");
header("Location: ../login.php?error_code=2");
根据错误代码,如果你想使用重定向,你会执行一个不同的函数。