3

这些是我的调用参数

$.post('checklogin_is.php', data, handleAjaxResponse, 'text');

回调函数是:

function handleAjaxResponse(data) {
   if($.trim(data)=='yes') 
      {
         //some more code 
      }
    else 
      {
         if($.trim(data)=='no')
            {
               //some code      
            }
         else
            {
               //some code
            }
          }         
        }

如您所见, checklogin_is.php 应该回显“是”或“否”。但是,我得到的不是那个,而是“是”或“否”,开头有一个额外的空格,因此我无法获得要由 if 语句评估的数据。

我正在使用$.trim(data)作为一种解决方法,但我想知道为什么我会得到这个额外的空白,以及是否有任何其他方法可以解决这个问题。提前致谢

php代码:

<?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'; 
?>
4

1 回答 1

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.

于 2012-09-23T00:52:07.157 回答