Stack Overflow / reddit voting system in php

一曲冷凌霜 提交于 2019-11-27 21:41:43

There are lots of scripts out there but it's not too hard to do yourself.

I've used jQuery (to handle AJAX) and a small PHP script before. For example, some pseudo-code:

// 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'));
}

and then some 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

You can use this one: http://www.technabled.com/2011/02/pulse-lite-reddit-ajax-up-down-voting.html Disclosure: I am the developer.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!