本文介绍了PHP中的Stack Overflow/Reddit投票系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for examples of how to implement a StackOverflow / reddit voting system in php.

基本上,我需要向上"和向下"箭头框.有没有好的例子?

Basically I want the Up and Down arrow box. Are there any good examples out there?

推荐答案

有很多脚本在那里,但是自己做起来并不难.

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

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

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

然后是一些jQuery:

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

这篇关于PHP中的Stack Overflow/Reddit投票系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:34