php redirect page is not open to new location but open in the div where ajax response text
PHP>ISSUE>PHP + AJAX + HTML FORM>REDIRECT [?]=NEW LOCATION.
(?)=PAge should be open in new page but open in the div #ajax
desire:Open in new page not in the div
HTML CODE:
<form id="form1" name="form1" action="login_success.php" onSubmit="return Ajxfunction()">
<input type="text" name="username" autocomplete="off" id="username">
<div id="validate"></div>
<input id="passowrd" type="password" autocomplete="off" name="password">
<div id="validate2"></div>
<input type="checkbox" name="checkbox" id="checkbox">
Stay Signed in <span>Forgetget Paswoard</span>
<br>
<input class="submit" id="button" type="button" value="SignIn" onClick=" Ajxfunction()" >
<div id="ajaxDiv"></div>
</form>
AJAX CODE
function Ajxfunction(){
var text= text2="";
var boolean=false;
var user = document.forms["form1"]["username"].value;
var password = document.forms["form1"]["password"].value;
if ( user==null || user == "") {
text = "Please Enter user name";
boolean=false;
} else {
text = "";
boolean=true;
}
if ( password==null || password == "") {
text2 = "Please Enter Password";
boolean=false;
} else {
text2 = "";
boolean=true;
}
document.getElementById("validate").innerHTML =text;
document.getElementById("validate2").innerHTML =text2;
if(boolean){
ajaxFunction();
}
//return true;
}
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var username1="";
var password1="";
username1=document.forms["form1"]["username"].value;
password1=document.forms["form1"]["password"].value;
var queryString = "?username=" + username1 ;
queryString += "&password=" + password1;
/* var queryString = "?username1=" + username1 ;
queryString += "&password1="+password1; /*+ "&sex=" + sex*/
ajaxRequest.open("GET", "Checklogin.php"+queryString, true);
ajaxRequest.send(null);
}
PHP CODE:Checklogin.php
<?php
$link = mysqli_connect('localhost','root','root','fly') or die("Error " .mysqli_error($link));
$user="";
$pass="";
if(isset($_GET['username'])){$user = $_GET['username'];}
if(isset($_GET['password'])){ $pass = $_GET['password'];}
$user = mysqli_real_escape_string($link,$user);
$pass = mysqli_real_escape_string($link,$pass);
/* $result = mysqli_query($link,"SELECT * FROM `useraccount` where username='$username' and password='$password' ");
*/
$msg="";
$result = mysqli_query($link,"SELECT * FROM `useraccount` where username='$user' && password='$pass' ");
$count = mysqli_num_rows($result);
try{
/*while($row = mysqli_fetch_array($result)) {
echo $row['username'] . " " . $row['password'];
echo "<br>";
}*/
if($count==1){
// session_start();
// $_SESSION["username"] = $user;
// $_SESSION["password"] = $pass;
// $_SESSION['login_user']=$result['useraccount']; //Storing user session value.
// $_SESSION['login_user']="HAroon"; //Storing user session value.
echo "Right Password";
header("Location:http://www.formget.com/app/");
// header('Location: login_success.php');
}
else {
$msg ="Wrong Username or Pdasswor";
mysqli_close($link);
}
}catch(Exception $e){
$msg= " Wrong";
}
echo $msg;
?>
========