Skip to content

Instantly share code, notes, and snippets.

@mentix02
Last active June 21, 2018 06:16
Show Gist options
  • Save mentix02/4f4a0470964f86235cb6ad7235cb4a97 to your computer and use it in GitHub Desktop.
Save mentix02/4f4a0470964f86235cb6ad7235cb4a97 to your computer and use it in GitHub Desktop.
an ajax call to update vote
$(function(){
$('.likeButton').click(function(){
let pk = this.id;
$.ajax({
url: '/post/like/',
type: 'POST',
data: {
pk: pk,
},
success: function(data) {
if (data['voted']) {
$('#' + pk).removeClass('btn-default').addClass('btn-success');
} else if (data['removed_vote']) {
$('#' + pk).removeClass('btn-success').addClass('btn-default');
} else {
console.log(data['error']);
}
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment