我正在使用ajax概念登錄表單請求。下面我發佈了與登錄相關的代碼。它不會重定向到myaccount.php頁面。如果我使用這個echo'<script>window.location="myaccount.php";</script>';
JavaScript函數,它將正常工作。但是,在這裏我想用php做。 它將myaccount.php結果作爲ajax消息返回。標題不重定向到另一個頁面ajax php
我得到使用此<div id="loginreturn"></div>
的錯誤消息。以上我發佈了一個錯誤圖片。 myaccount.php頁面的結果也顯示在<div id="loginreturn"></div>
裏面。這是我的問題。它不會重定向到另一個PHP頁面。如何解決這個錯誤?
的login.php
<?php
ob_start();
include('config.php');
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$user_email = $_POST['email'];
$user_password = $_POST['password'];
$_SESSION['ses_uemail'] = $user_email;
if(empty($user_email) || empty($user_password))
{
echo "You must provide your email id and password";
die();
}
try
{
$stmt = $conn->prepare("SELECT * FROM table_name WHERE EmailID = ? AND Password = ?");
$conn->errorInfo();
$stmt->bindParam('1', $user_email, PDO::PARAM_STR);
$stmt->bindParam('2', $user_password, PDO::PARAM_STR);
$stmt->execute();
while($row = $stmt->fetch())
{
$rename = $row['Name'];
$reemail = $row['EmailID'];
$repassword = $row['Password'];
}
if($reemail == $_SESSION['ses_uemail'] && $repassword == $user_password)
{
$_SESSION['ses_name'] = $rename;
$_SESSION['ses_email'] = $reemail;
$_SESSION['ses_password'] = $repassword;
header('Location:myaccount.php');
}
else
{
echo "Incorrect email id and password";
}
}
catch(PDOException $e)
{
'Error : ' .$e->getMessage();
}
}
ob_flush();
?>
ajax.js
// ajax signin
jQuery(document).ready(function() {
jQuery("#registertologin").click(function() {
jQuery("#loginreturn").html("<img src='img/loading.gif'/>");
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax({
url : 'login.php',
type: "POST",
data : $('#loginform').serialize(),
success:function(data, textStatus, jqXHR) {
jQuery("#loginreturn").html('<pre><code class="returndata">'+data+'</code></pre>');
$("#loginform").submit_login(); //SUBMIT FORM
},
error: function(jqXHR, textStatus, errorThrown)
{
$("#loginreturn").html('<pre><code class="returndata">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
e.preventDefault(); //STOP default action
});
});
的index.php
<form name="loginform" id="loginform" >
<table class="outlineborder" width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="35" colspan="2">
<div class="signinform">SignIn Form</div>
</td>
</tr>
<tr>
<td height="35" colspan="2"> </td>
</tr>
<tr>
<td width="150" height="35" class="rightalign">Email Id : </td>
<td width="348"><input class="inputfield" type="text" name="email" /></td>
</tr>
<tr>
<td height="35" class="rightalign">Password : </td>
<td><input class="inputfield" type="password" name="password" /></td>
</tr>
<tr>
<td height="35" colspan="2" align="right">
<span class="forgetpassword">Forget Password ?</span>
</td>
</tr>
<tr>
<td height="35" colspan="2" align="center">
<div id="loginreturn"></div>
</td>
</tr>
<tr>
<td height="35" colspan="2" align="center">
<input class="btns" type="button" name="submit_login" id="registertologin" value="SignIn" />
<input class="btns" type="button" value="Close" onclick="document.getElementById('login_signup').style.display='none'; document.getElementById('fade').style.display='none'" />
</td>
</tr>
</table>
</form>
爲什麼你把標題:在登錄頁面(「位置myaccount.php」),你應該把在成功的函數調用Ajax –
爲什麼downvotes? – Karuppiah