Javascript jqueryajax中的问题

Javascript jqueryajax中的问题,javascript,jquery,Javascript,Jquery,我使用这个jquery函数向abc.php发送请求; 返回的x值是正确的,但不管它的值是什么,只执行if;即使x为false,也不会执行else $.post('abc.php',{u:e1.value},function(x){ document.getElementById('d').innerHTML+=" x="+x; if(x){ document.getElementById('d').style.color="green"; document.getElementB

我使用这个jquery函数向abc.php发送请求; 返回的x值是正确的,但不管它的值是什么,只执行if;即使x为false,也不会执行else

$.post('abc.php',{u:e1.value},function(x){
document.getElementById('d').innerHTML+=" x="+x;
if(x){
    document.getElementById('d').style.color="green";
    document.getElementById('d').innerHTML+="<img src='t.jpeg'>";
    q=true;
    }
else{
    document.getElementById('d').style.color="red";
    document.getElementById('d').innerHTML+="U";
    q=false;
    }document.getElementById('f').innerHTML+=" q="+q;
    });
}
这是abc.php文件

<?php
$db = "b";
$link = mysql_connect("localhost","root","");
mysql_select_db($db, $link) or die(mysql_error());
$q = "select * from us where ad='$_POST[u]'";

$r=mysql_query($q, $link) or die(mysql_error());

if(mysql_num_rows($r)==1)
echo true;
else echo false;
mysql_close($link) or die(mysql_error());
?>

您正在检查的数据是字符串而不是布尔值


您的测试应该是:x===true,尽管您可能需要考虑PHP输出中的空白。

我认为问题在于您正在回显变量,因此数据被视为字符串,因此,如果它为true或false,则始终设置变量,这意味着x为true

尝试将语句更改为ifx.toLowerCase==true


您可以添加一个进一步的=来检查它是否确实是一个字符串

数据被视为字符串,而不是布尔值。 而且,你是在呼应布尔而不是弦

Javascript:

 if(x == 'true')

我更改了代码以检查字符串,但仍然存在问题。这可能是因为空白。x=jQuery.trim$this.text;x=x.replace//g,;x=jQuery.trimx;x=$this.text.replace//g,;我尝试了一些方法来去除空白。但似乎不起作用,空白仍然存在。为什么呢?谢谢你的帮助。我做了改变,但没有解决问题;可能是因为空白吗?
  echo "true" ;
 and echo "false";
 if(x == 'true')