3

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'; 
?>
Luis_DV
  • 73
  • 5

1 Answers1

1

Make sure there is no whitespace in the file before <?php session_start();; this would not only be echoed, but will also break your session.

Another thing to try is checking to see if any included files (e.g. "is-c.php") have whitespace outside of any PHP tags. Note that you can leave off any closing PHP tags at the end of files to make sure there are no newline characters being echoed.

Owlvark
  • 1,763
  • 17
  • 28
  • Thanks for the suggestion @owlvark. I have made sure there is no withespace before that line but I'm still having the same result. Any other suggestion? – Luis_DV Sep 24 '12 at 07:36
  • I have checked all my included files and I already made sure I have not a whitespace outside the PHP tag, but I'm still getting the same result – Luis_DV Oct 04 '12 at 04:36
  • This is very strange. Can you post "is-c.php"? – Owlvark Oct 04 '12 at 23:38