Php 我做错了什么?没有错误
msg,我得到的回应:(firebug)Php 我做错了什么?没有错误,php,jquery,ajax,Php,Jquery,Ajax,msg,我得到的回应:(firebug) -吉隆坡。01:55 DETTE-ER-EN试验 它正确地发送和执行ajax调用,并且它有响应,但是它不切换它 这是分区: <span class='userWallComment'> <span style='float: left;'> <img style='border: 1px solid #ccc; width: 44px; height: 48px; margin-right: 8px;' sr
-吉隆坡。01:55
DETTE-ER-EN试验
它正确地发送和执行ajax调用,并且它有响应,但是它不切换它
这是分区:
<span class='userWallComment'>
<span style='float: left;'>
<img style='border: 1px solid #ccc; width: 44px; height: 48px; margin-right: 8px;' src='images/profilePhoto/thumbs/noPhoto_thumb.jpg'>
</span></span>
<span style='font-size: 10px; margin-bottom: 2px;'>
<a href='profil.php?id=1'>Navn navn</a> - igår kl. 01:55
</span>
<br>
DETTE ER EN TEST
<br>
<div class="clearfloat"></div>
</span>
问题
您的if
-else
语句有缺陷:
<div id="showWallCommentsFor<?php echo $displayWall["id"]; ?>" style="display: none;">
</div>
第一次启动AJAX调用时,#showwallcomentsfor
为空,因此它没有。因此,不会定义$msg
。
解决方案
您应该使用以下方法将文本直接添加到else
中的原始div中:
if ( $msg.text().length ) {
// ...
} else {
// $msg has a length of ZERO by definition here!!!
$msg.hide().text( msg ).slideToggle(300);
}
最后,在你的else
中,没有必要.hide()
这个#showWall…
div,因为在我的大脑中,这个div本来是不可见的,因为style=“display:none;”“
@Tomalak-。。。单独地我的意思是$msg,这就是为什么在继续之前应该检查$msg.text().length。-为了抓鱼。
if ( $msg.text().length ) {
// ...
} else {
// $msg has a length of ZERO by definition here!!!
$msg.hide().text( msg ).slideToggle(300);
}
if ( $msg.text().length ) {
// ...
} else {
// otherwise just hide it, add the text, and then toggle it in
// You cannot use $msg here, since it has a length of 0.
// Add text directly to the original div instead.
// You do not need to hide the DIV first since it is already
// invisible.
$('#showWallCommentsFor'+wallID).text( msg ).slideToggle(300);
}