Javascript 什么是不可见但不“的字符串?”&引用?ajax php mysql
我正在编写一个聊天程序,为此,我向一个php文件发送了一个ajax请求,并得到了werner的msg回复。但它不仅仅是一个字符串,因为msg.length显示13个字符。 我以为它可能是空字符串,但不是因为Javascript 什么是不可见但不“的字符串?”&引用?ajax php mysql,javascript,ajax,request,Javascript,Ajax,Request,我正在编写一个聊天程序,为此,我向一个php文件发送了一个ajax请求,并得到了werner的msg回复。但它不仅仅是一个字符串,因为msg.length显示13个字符。 我以为它可能是空字符串,但不是因为 if(msg[i]==" ") 不是真的 msg[i]=="" 也不是真的,但是typeof(msg[i])显示它确实是一个字符串 那会是什么呢 我需要知道的原因是因为我想问如果(werner==msg),但它传递的是false,因为msg中有一些空字符串,有13个字符,而不是6个字
if(msg[i]==" ")
不是真的
msg[i]==""
也不是真的,但是typeof(msg[i])
显示它确实是一个字符串
那会是什么呢
我需要知道的原因是因为我想问如果(werner==msg)
,但它传递的是false,因为msg
中有一些空字符串,有13个字符,而不是6个字符
这就是我的js代码的样子:
$.ajax({
type:"POST",
url:"ausmisten.php",
success:function(msg){
alert(msg);//shows werner
alert(typeof(msg));//String
alert(msg.length);//13
if(msg=="werner")//not true
$("#Abmelden").click();//not executed
}
});
php文件
echoes "werner"
php文件中的重要部分是:
$result=mysqli_query($db,"select distinct name from Datenbank1");
$array=mysqli_fetch_array($result);
echo $array[0];//$array[0]="werner"
我将问题更改为ausmisten.php空php文件
和TEST.html
<!doctype html>
<html>
<head>
<title>
Versuch
</title>
</head>
<body>
<div id="ausgabe"></div>//8string is shown
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$.ajax({
type:"POST",
url:"ausmisten.php",
success:function(msg){
$("#ausgabe").html(msg+msg.length+typeof(msg));
}
});
</script>
</html>
即使是一个空站点也会发送一些空字符串,您必须删除这些空字符串您能显示一些代码吗?请尝试
var\u dump($msg)代码>(假设“werner”在$msg中)以查看它到底包含什么。您确定这是一个PHP问题吗typeof
是一个JS thingTanks,但它是javascript,而不是php,但我从php文件中得到了响应
8string