2009-01-29 55 views

回答

6

有很多腳本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