首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多帖子评论系统

多帖子评论系统
EN

Stack Overflow用户
提问于 2011-12-30 22:22:49
回答 1查看 647关注 0票数 0

我有一个stackoverflow风格的评论系统,其中有一个可变数量的帖子(“答案”)在一个页面上,人们可以评论。我正在尝试使用jquery来获取用户评论的唯一选择器,将其提交到mysql数据库中并显示它,所有这些都不需要刷新。问题是我不知道如何选择单个评论,因为评论需要有一个唯一的选择器,而现在它们都在同一个类(.commentBox)下。

JQUERY:

代码语言:javascript
复制
<script type='text/javascript'>
$('document').ready(function(){

$('.submitCommentBox').click(function(){

            var comment = $('  //idk ').valu();
            var questionid = $(' //idk  ').val();
            var answerid=$('  //idk  ').val();

    $.post('../comment.php',
    {

    comment: comment,
    questionid: questionid,
    answerid: answerid,


    },
    function(response){

        $('#commentContainer').load('../writecomment.php');

    });

}):

});

</script>

HTML (这是在while循环中,根据帖子的数量进行多次回显):

代码语言:javascript
复制
                 <div class='answerContainer'>
                    <p name='singleAnswer' value='$answerid[$f]'>$answer[$f]</p>
                    <p>$answeruser[$f]</p>
                    <p> $time[$f] seconds</p>
                    <p> $answerrating[$f]</p>
                    <form id='form$c'>
                    <div id='commentContainer'></div>
                    <textarea class='commentBox' placeholder='...comment' wrap='soft' name='comment' value='$c'></textarea>
                    <input type='button' value='submit' class='submitCommentBox'>
                    </form>
                    </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-13 06:46:30

您可以在表单上执行此操作,只需将submit按钮更改为type=" submit“,而不是在提交上执行此操作。

代码语言:javascript
复制
$('.addCommentForm').submit(function(){
    $.post({
        type: 'POST',
        url: '../comment.php',
        data: $(this).serialize(),   // $(this) referring to the source form that triggered the submit.
        success: function(data, textStatus, jqXHR) {
            // Do whatever like add the display only equivalent of the comment
            // that was just submitted if successful.
        }
    });
    return false; // Prevent the form from actually submitting the old fashion way.
});

我会参考jquery api来了解更多细节。http://api.jquery.com/jQuery.post/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8680425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档