My script is a simple like and dislike buttons (called reactions). It works well but now I want to have a quick cookie created if the vote went through so people can't vote for this particular comment ever again (ie. 1 year.. or when they remove their cookies.)
The entire function works but I am confused on how to add the cookie for each specific comment they have reacted to?
(function( $ ) {
'use strict';
$( document ).ready(function() {
$(document).on('click', '.enco-reaction', function(e){
var data = {
'action': 'enco_reaction',
'reaction': $(this).data('reaction'),
'comment': $(this).data('id')
};
$.post(
ajax_object.ajax_url,
data,
function( obj ) {
if( obj.error ) {
alert( obj.error );
} else {
$('#enco-reaction-' + obj.reaction + '-' + obj.comment + ' .enco-reaction-count' ).html( obj.value );
}
},
'json'
);
});
});
})( jQuery );