게시물 목록을 연결하여 사용자가 각 게시물에 댓글을 달 수 있습니다. 또한 댓글은 jquery를 통해 실시간 업데이트됩니다. 각 게시물에 대해 고유 한 변수를 사용하고 있기 때문에 업데이트 div의 ID 끝으로 붙여 넣기 만하면됩니다. 제출 버튼 클래스 끝 부분에 붙여 넣기 :댓글 시스템 - 연결 중
$my_list .= '
<form action="#" method="post">
<textarea class="commentbox" name="comment" id="comment"></textarea>
<input type="hidden" name="post_id" id="post_id" value=' . $post_id . ' />
<input type="hidden" name="member_id" id="member_id" value=' . $id . ' />
<input type="submit" class="submit' . $post_id . '" value="Comment " />
</form>
' . $comment_list . ' // existing comments queried from the db
<ol id="update' . $post_id . '"></ol> // jquery-ed live update comments
';
?>
위와 관련된 모든 사항이 훌륭하게 보입니다 (즉, 각 제출 버튼은 고유 한 클래스를 가지며 각 업데이트 div는 고유 한 ID를 갖습니다).
그래서 지금 당면한 문제는 다음과 같습니다. 고유 한 "제출"을 각각 어떻게 인식 할 수 있습니까? 이것은 내가 지금 가지고있는 것입니다 (아래). 하지만 게시물 옆에있는 제출 버튼을 클릭 할 때마다 아무 일도 일어나지 않으며 내 페이지가 새로 고침되고 URL 끝에 "#"이 추가됩니다. 내 라이브 http 헤더를 확인하고 주석이 올바른 고유 $ post_id와 함께 게시되고있는 것처럼 보입니다 ...하지만 js 함수에서 멈추는 것 같습니다.
<head>
<script type="text/javascript">
$(function() {
$(".submit<?php echo $post_id; ?>").click(function() {
var post_id = $("#post_id").val(); // this is the unique id for each story, in a hidden input
var member_id = $("#member_id").val(); // this is a member for the commenter, in a hidden input
var comment = $("#comment").val(); // this is the comment from the input box
var dataString = 'post_id='+ post_id + '&member_id=' + member_id + '&comment=' + comment;
if(comment=='') {
alert('Please enter a valid comment');
} else {
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="loading">Loading Comment...</span>');
$.ajax({
type: "POST",
url: "commentajax.php",
data: dataString,
cache: false,
success: function(html){
$("#update<?php echo $post_id; ?>").append(html);
$("#update<?php echo $post_id; ?> li:last").fadeIn("slow");
document.getElementById('post_id').value='';
document.getElementById('member_id').value='';
document.getElementById('comment').value='';
$("#comment").focus();
$("#flash").hide();
}
});
}
return false;
});
});
</script>
</head>
그냥 물어 보면 게시물 목록이 있으며 각 게시물에는 이와 같은 별도의 기능이 있습니다! –
예. 게시물 목록입니다 ... 그러나 html의
에있는 함수는 하나뿐입니다. – Jet59black선택자'$ (". submit php echo $ post_id;?>")'가 '게시 ID'를 가지고 있기 때문에 왜 이런 질문을했는지 알지 못했습니다. 페이지! ;-) –