1
I put this library switchery
in my project, I can capture the checkbox change event, but not make sure that if the post goes wrong it returns to unchecked.
$('.js-switch-small').on('click',function() {
var ted = $(this);
var id = ted.attr('id');
var status = ted.prop( "checked");
$.ajax({
url : "post.phpp",
type: "POST",
data: {
user: id,
status:status,
},
dataType: 'json',
error: function(data){
alert('error '+status);
//entra em loop
$(ted).trigger('click');
},
success: function(data){
alert('sucesso');
//$('#retorno').html(data);
}
});
});