Update button after AJAX call
Update button after AJAX call
I'm using Datatables to display about 20 records and one of my columns contains a group of buttons. One of those buttons is a simple toggle button that, when clicked, sends an AJAX request back to the server and then updates the button (starred vs. not starred using Font Awesome icons) based on the response. The button and AJAX request seem to work fine, but I can't seem to make the star fill in or empty after the AJAX call. Here is my JS:
$('.btn-is_starred').click(function(e) {
e.preventDefault();
$.post( $(this).attr('href'), function( data ) {
if (data.is_starred == true) {
$(this).html('<i class="fa fa-star"></i>');
}
else {
$(this).html('<i class="fa fa-star-o"></i>');
}
});
});
Any advice?