bootstrap switchで前の値に戻す処理をメモ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$(document).on('switchChange.bootstrapSwitch', '.switch-button', function(event, state) { // 何か処理してエラーになったら $.ajax( { url: '/xxx/xxx/xxx', type: 'post', dataType : 'json', success: function( data ) { // 成功 }, error: function( data ) { // 失敗したので前の値に戻す $(".switch-button").trigger('previousState.bootstrapSwitch', true); }, complete: function( data ) { } }); } |
ってなる。