Home > Web Front-end > JS Tutorial > body text

Voting System Javascript

Barbara Streisand
Release: 2024-09-22 16:30:39
Original
240 people have browsed it

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);
            }
        });
    }
Copy after login

`

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

source:dev.to
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!