0
我希望在使用AJAX對錶單進行驗證之後,它將被重定向到另一個頁面,但是我的編碼在specfic <div id="result">
中顯示結果。我在index.php上用下面的代碼得到這個結果:帶有AJAX結果的URL重定向
<div class="c_right">
<div>
<div class="t_h_c">
Hi Guest
</div>
<div id="result" class="error">
</div>
<div class="username">
Username:
</div>
<form name="signin" id="signin" method="post">
<div class="f_l2">
<input type="text" class="form_username" name="username" maxlength="40">
</div>
<div style="clear:both;">
</div>
<div class="username">
Password:
</div>
<div class="f_l2">
<input type="password" class="form_username" name="pass" maxlength="50">
</div>
<div style="clear:both;">
</div>
<div class="username"></div>
<div class="f_l2">
<a href="javascript:void(0)" onclick="document.getElementById('light3').style.display='block';document.getElementById('fade3').style.display='block'">
<img src="img/jpg/sinup.png" />
</a>
</div>
<div class="f_r">
<img src="img/jpg/sin-in.png" onClick="showHint()" />
</form>
</div>
</div>
</div>
<script type="text/javascript">
// function create GetXmlHttpObject
function showHint()
{
var t2lFname=document.signin.username.value;
var t2lLname=document.signin.pass.value;
var parameters="firstname="+t2lFname+"&lastname="+t2lLname;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState == 1)
{
document.getElementById("chart").innerHTML ="<img src='img/ajax-loader.gif' />";
}
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","thank-you.php?username="+t2lFname+"&pass="+t2lLname,true);
xmlhttp.send();
}
</script>
以下是thank-you.php的代碼。我希望驗證後,index.php將在validation.php結果顯示爲resulty id後移至members.php。
<?php
echo $_REQUEST['username'];
echo $_REQUEST['pass'];
include("connection.php");
$query = mysql_query("SELECT COUNT(*) FROM user");
list($number) = mysql_fetch_row($query);
//Checks if there is a login cookie
//if the login form is submitted
if (isset($_REQUEST['username'])) { // if form has been submitted
// makes sure they filled it in
if(!$_REQUEST['username'] | !$_REQUEST['pass']) {
die ('<span class="eror">You did not fill in a required field.</span>');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_REQUEST['email'] = addslashes(@$_REQUEST['email']);
}
$check = mysql_query("SELECT * FROM user WHERE un = '".$_REQUEST['username']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die ("User name does not exist");
}
while($info = mysql_fetch_array($check))
{
$_REQUEST['pass'] = stripslashes($_REQUEST['pass']);
$info['password'] = stripslashes($info['password']);
$_REQUEST['pass'] = md5($_REQUEST['pass']);
//gives error if the password is wrong
if ($_REQUEST['pass'] != $info['password']) {
die ('<span class="eror">Incorrect password,<i> please try again.</i></span>');
}
else
{
// if login is ok then we add a cookie
$_REQUEST['username'] = stripslashes($_REQUEST['username']);
$hour = time() + 600000000000000000000000000;
setcookie(ID_my_site, $_REQUEST['username'], $hour);
setcookie(Key_my_site, $_REQUEST['pass'], $hour);
include("time.php");
$conform=mysql_query("INSERT INTO user_ts (user_ts_user,user_ts_uli,user_ts_date, user_ts_umd) VALUES ('$_REQUEST[username]','$x','$d','$time_code')");
if ($conform)
{
//then redirect them to the members area
setcookie('md',$time_code);
setcookie('li',$x);
setcookie('h',$h);
setcookie('m',$m);
# index.php is moved to members.php
header("Location: members.php");
}
else
{
die ('Not Inserted');
}
}
}
}
else
{
// if they are not logged in
}
}
?>