i am creating login page with ajax.when user name and pass is wrong it should display error and when pass is right it should redirect to another page.but here in both case success function is called..
<script>
$(document).ready(function()
{
$("#simple-post").click(function()
{
$("#ajaxform").submit(function(e)
{
$("#simple-msg").html("<img src='loading.gif'/>");
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
alert(data.status);
$("#simple-msg").html('<pre><code class="prettyprint">'+data+'</code></pre>');
},
error: function(jqXHR, textStatus, errorThrown)
{
$("#simple-msg").html('<pre><code class="prettyprint">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
e.preventDefault(); //STOP default action
});
$("#ajaxform").submit(); //SUBMIT FORM
});
});
</script>
this is php
<?php
ob_start();
include 'CUserDB.php';
session_start();
include 'config.php';
$myusername=$_POST['txtusername'];
$mypassword=$_POST['txtpassword'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword=mysql_real_escape_string($mypassword);
$qry = "SELECT UserName,Type_user FROM login WHERE UserName = '".$myusername."' AND password = '".$mypassword."' ";
$result = mysql_query($qry) or die ("Query failed");
$UserData = mysql_fetch_array($result);
if($UserData['UserName'] != '')
{
session_start();
$_SESSION['UserId'] = $myusername;
$typ = $UserData['Type_user'];
if ( $typ == "Dealer")
{
header('location:Dealer/EditLoginDetails.php');
}
else if ($typ == "Individual")
{
header('location:/Dealer/EditLoginDetails.php');
}
else
{
header('location:/Builder/managep.php');
}
}
else
{
echo " wrong username or password";
}
?>
i want to display wrong username pass if not success..how to do this please i am new in ajax