2009-01-29 8 views

Répondre

6

Il y a beaucoup de scripts out there mais ce n'est pas trop difficile à faire soi-même.

J'ai utilisé jQuery (pour gérer AJAX) et un petit script PHP auparavant. Par exemple, certains 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')); 
} 

puis certains 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