Last active
June 21, 2018 06:16
-
-
Save mentix02/4f4a0470964f86235cb6ad7235cb4a97 to your computer and use it in GitHub Desktop.
an ajax call to update vote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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