我目前正在嘗試使用戶點擊「打開評論」後發出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