I have a jQuery ajax code that works perfectly. But I need it to change the class of the button that fires the jQuery ajax event when clicked when successful. But my code on sucess: doesn't work. Please see code below.
jQuery Code
$(document).ready(function() {
$('.btn.btn-outline.btn-sm').click(function() {
var pollQId = $(this).val();
$.ajax({
type: "POST",
url: "Default.aspx/LikePoll",
data: JSON.stringify({ 'pollQId': pollQId }),
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function() {
$(this).addClass("btn btn-primary btn-sm");
},
error: function(response) {
alert(response.d);
}
});
});
})
Please help me. Many Thanks.