Javascript 就像指望使用cakephp发布帖子一样

Javascript 就像指望使用cakephp发布帖子一样,javascript,cakephp-2.0,Javascript,Cakephp 2.0,我有两个模型用户(id、用户名、密码),Post(id、User_id、body、created、liked、disliked),如果任何用户喜欢或不喜欢某个帖子,我想显示喜欢或不喜欢的总数。我用它来实现它对我不起作用,请有人告诉我怎么做 这是我的邮政管理员: function voteUp($id = null) { if ($this->RequestHandler->isAjax()) { $this->Post->id = $id;

我有两个模型用户(id、用户名、密码),Post(id、User_id、body、created、liked、disliked),如果任何用户喜欢或不喜欢某个帖子,我想显示喜欢或不喜欢的总数。我用它来实现它对我不起作用,请有人告诉我怎么做

这是我的邮政管理员:

function voteUp($id = null) {
    if ($this->RequestHandler->isAjax()) {
        $this->Post->id = $id;
        if ($this->Post->saveField('liked', $this->Post->field('liked') + 1)) {

        }
    }
    $newValue = $this->Post->findById($id);
    return $newValue['post']['liked'];
}

function voteDown($id = null) {
    if ($this->RequestHandler->isAjax()) {
        $this->Post->id = $id;
        if ($this->Post->saveField('disliked', $this->Post->field('disliked') + 1)) {

        }
    }
    $newValue = $this->Post->findById($id);
    return $newValue['Post']['disliked'];
}
这是我的帖子/查看文件:

<div class="voteup" style="margin-left:10px;float:left;width:55px;">
    <p style="display:none;float:left">
        <?php echo $post['Post']['id']; ?>
    </p>
    <div style="float:left" id="article_thumbsUp">
        <?php echo $post['Post']['liked']; ?>           
    </div>                                                      
    <img width="20" src="/img/icons/thumb-up-icon.png">
</div>
<div class="votedown" style="float:left;width:55px;">
    <p style="display:none;float:left">
        <?php echo $post['Post']['id']; ?>
    </p>
    <div style="float:left" id="article_thumbsDown">
        <?php echo $post['Post']['disliked']; ?>                                
    </div>                      
    <img width="20" src="/img/icons/thumb-down-icon.png">
</div>

这是我的类似js的文件:

<script>
    $(document).ready(function() {
        $(".voteup").click(function() {
            var Id = $(this).children("p").text();
            $(this).children("#article_thumbsUp").load("/posts/voteup/" + Id);
        });
    });
</script>

<script>
    $(document).ready(function() {
        $(".votedown").click(function() {
            var Id = $(this).children("p").text();
            $(this).children("#article_thumbsDown").load("/posts/votedown/" + Id);
        });
    });
</script>

$(文档).ready(函数(){
$(“.voteup”)。单击(函数(){
var Id=$(this.children(“p”).text();
$(this.children(“#article_thumbsUp”).load(“/posts/voteup/”+Id);
});
});
$(文档).ready(函数(){
$(“.votedown”)。单击(函数(){
var Id=$(this.children(“p”).text();
$(this.children(“#article_thumbsDown”).load(“/posts/votedown/”+Id);
});
});

uhhh。。如果可能,只需发布与您的需求相关的代码。眼睛很疼。哪一块坏了,哪一块坏了?你们需要更具体一些。它只在帖子下面显示“喜欢”和“不喜欢”图标,但并没有链接,若我点击图标,什么也不会发生。如果任何用户喜欢或不喜欢一篇文章,我的第一个目标是显示喜欢/不喜欢的总数,如果可能的话,显示他们的用户名。什么不起作用?VoteUP或VoteDown或两者都有?@user3792730这就是你的问题,你的jquery脚本没有执行