我目前正在尝试使用户点击“打开评论”后发出ajax评论功能。获取兄弟姐妹jquery/ajax的孩子的价值?
目前我从我的php脚本获取数据,并且ajax调用的状态为“200 OK”,因此它定义了工作,但我无法为当前已被点击的评论获取正确的值为了将其发布到PHP脚本。
我在问的是如何获得".posted_comment_id"
类的价值,然后如何加载返回到".commentView"
类的数据?
的jQuery/AJAX:
$(".closedComment").click(function(){
var $this = $(this);
$this.hide().siblings('.openComment').show();
$this.siblings().next(".commentBox").slideToggle();
$.ajax({
type: "POST",
url: "http://example.dev/comments/get_timeline_comments",
data: {post_id: $this.siblings().next(".commentBox").find(".posted_comment_id").val()},
dataType: "text",
cache:false,
success:
function(data){
$this.closest(".commentView").load(data);
}
});
return false;
});
HTML:
<div class="interactContainer">
<div class="closedComment" style="display: none;">
<a href="#" class="floatLeft rightMrgn">open comments</a>
</div>
<div class="openComment" style="display: block;">
<a href="#" class="floatLeft rightMrgn">close comments</a>
</div>
<div class="commentBox floatLeft" style="display: block;">
<form action="http://example.com/comments/post_comment" method="post" accept-charset="utf-8">
<textarea name="comment" class="inputField"></textarea>
<input type="hidden" name="post" value="13">
<input type="hidden" name="from" value="5">
<input type="hidden" name="to" value="3">
<input type="submit" name="submit" class="submitButton">
</form>
<div class="commentView"></div>
<div class="posted_comment_id" style="display:none;">13</div>
</div>
</div>
谢谢,这是很好的作品,但我如何将这些数据加载到'.commentView'? – learn
@learn在成功回调中,您可以再次使用'text'或'html'方法将其作为新内容放在那里。 – Broxzier
可否详细说明一下? – learn