【问题标题】:Stack Overflow / reddit voting system in phpphp 中的 Stack Overflow / reddit 投票系统
【发布时间】:2010-10-04 04:59:10
【问题描述】:

我正在寻找如何在 php 中实现 StackOverflow / reddit 投票系统的示例。

基本上我想要向上和向下箭头框。有什么好的例子吗?

【问题讨论】:

    标签: php voting


    【解决方案1】:

    有很多脚本out there,但自己做并不难。

    我以前使用过 jQuery(处理 AJAX)和一个小的 PHP 脚本。比如一些伪代码:

    // Some checking for recent votes from this user is appropriate here
    if (isset($_POST['voteType'], $_POST['postId']) && $user->loggedIn) {
        // insert vote into database if not already inserted
        echo json_encode(array('error' => false));
    } else {
        // bad request/hack attempt
        echo json_encode(array('error' => true, 'message' => 'Bad parameters sent'));
    }
    

    然后是一些 jQuery:

    $('#upVote').click(function() {
        $.post('vote.php', {voteType: 'up', postId: 42}, 'updateIcon(data, textStatus)', 'json');
    });
    
    function updateIcon(data, textStatus) {
        // If error = false highlight the upvote icon
        // else show the error message returned
    }
    

    jQuery.post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多