2015-09-17 16:54:46 +02:00

36 lines
929 B
JavaScript

$( document ).ready(function() {
$('.vote_box').on('click', '.vote', function(e){
var boxes = $(this).parent('.vote_box');
var id_post = $(this).data('id');
var uri = baseUri+'modules/cmsps/ajax_voting.php';
$.ajax({
url : uri,
type : 'POST',
data : 'id_post=' + id_post,
dataType : 'json',
success : function(json, statut) {
if(!json.errors) {
$(boxes).addClass('active');
if (json.already_vote) {
if($(boxes).children('.already_vote').length == 0) {
$(boxes).append('<span class="already_vote">Déjà voté</span>');
}
} else {
if($(boxes).children('.already_vote').length == 0) {
$(boxes).append('<span class="already_vote">Merci</span>');
}
$('.nb_vote_'+id_post).each(function(index) {
$(this).html(json.nb_vote);
});
}
}
},
error : function(resultat, statut, erreur) {
},
});
});
});