如何从PHP if-else语句运行return to login file和jQuery函数
我有以下PHPIF/else语句-我如何告诉它返回login.PHP并运行jQuery函数如何从PHP if-else语句运行return to login file和jQuery函数,php,Php,我有以下PHPIF/else语句-我如何告诉它返回login.PHP并运行jQuery函数 if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_
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');
或
在login.php
中的javascript标记上:
您可以使用php
进行以下操作:
<?php if($_GET['message'] == 'query_failed'): ?>
jquery_query_failed_function();
<?php elseif($_GET['message'] == 'login_failed'): ?>
jquery_login_failed_function();
<?php endif; ?>
根据错误代码,如果您想使用重定向,您将执行不同的函数。您应该从login.php使用AJAX调用此函数,然后在回调中调用jQuery函数。您的问题有点含糊不清。。。你是通过Ajax调用这个脚本的吗?@Felix-让我在login.php文件中通过。@Felis-这是我的login.php文件这个名字是固定的还是我可以随便叫它什么jquery\u query\u failed\u函数
您可以调用任何jquery或javascript函数:)这只是为了简化概念FireBug说,$('p.error').LoginMissing();正在取消查找
。为什么?与此同时,我刚刚将$\u GET
中的某些内容更正为$\u GET['message']
,以及中的一些内容如果是endif
语法,请适当地更正它们,为什么不使用$.loginFailed()代码>而不是$('p.error')。loginFailed();
<?php if($_GET['message'] == 'query_failed'): ?>
jquery_query_failed_function();
<?php elseif($_GET['message'] == 'login_failed'): ?>
jquery_login_failed_function();
<?php endif; ?>
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");