These are my calling parameters
$.post('checklogin_is.php', data, handleAjaxResponse, 'text');
The callback function is:
function handleAjaxResponse(data) {
if($.trim(data)=='yes')
{
//some more code
}
else
{
if($.trim(data)=='no')
{
//some code
}
else
{
//some code
}
}
}
As you can see checklogin_is.php should echoes either "yes" or "no". However, instead of that, I get " yes" or " no" with an extra white space in the beginning therefore I can't get the data to be evaluated by the if statements.
I'm using $.trim(data)
as a workaround but I would like to know why I'm getting this extra white space and if there is any other way to fix this up. Thanks in advance
php code:
<?php session_start();
require_once('D:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\is-c.php');
$un = htmlspecialchars($_POST['usnm'],ENT_QUOTES);
$unp = $_POST['usnmp'];
$query_lg = "SELECT * FROM incm_s WHERE s_un='".$un."'";
$user_row = $isdb->get_row( $query_lg, ARRAY_A);
if($user_row['s_id'] > 0)
{
if(strcmp($user_row['s_pd'],$unp)==0)
{
$_SESSION['un_is']=$user_row['s_un'];
$_SESSION['utype_is']=$user_row['s_type'];
echo 'yes';
}
else
echo 'no';
}
else
echo 'no';
?>