Problem with library switchery

Asked

Viewed 53 times

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);
        }
    });
});

1 answer

0

simply remove the checked property from the checkbox.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.