Home  >  Article  >  Web Front-end  >  Voting System Javascript

Voting System Javascript

Barbara Streisand
Barbara StreisandOriginal
2024-09-22 16:30:39354browse

Voting System Javascript

Working on a project here at jhoom.xyz and have stuck at a place where I would like to limit voting per IP.
` function voteReview(reviewId, voteType) {
const data = {
action: 'ipf_vote_review',
reviewId: reviewId,
voteType: voteType,
postId: ID; ?>
};

        jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
            if (response.success) {
                const reviewElement = jQuery('.single-review').eq(reviewId);
                if (voteType === 'up') {
                    let upCount = parseInt(reviewElement.find('.thumb:first').text().match(/\d+/)[0]) + 1;
                    reviewElement.find('.thumb:first').html('&#128077; (' + upCount + ')');
                } else {
                    let downCount = parseInt(reviewElement.find('.thumb:last').text().match(/\d+/)[0]) + 1;
                    reviewElement.find('.thumb:last').html('&#128078; (' + downCount + ')');
                }
            } else {
                alert(response.data);
            }
        });
    }

`

The above is the detailed content of Voting System Javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn