//https://gist.github.com/havvg/3226804 //http://1000hz.github.io/bootstrap-validator/ //$(document).validator().on('submit', 'form[data-async]', function(e) { // va in conflitto con form data-sync $('form[data-async]').validator().on('submit', function(e) { $.fix_theme_callback(); if (!e.isDefaultPrevented()) { e.preventDefault(); var $form = $(this); var $target = $form.attr('data-target'); var $response = $form.find('.response'); var $btn = $form.find('button[type="submit"]').button('loading'); var $dismiss = ''; //http://stackoverflow.com/a/15824920 if ( $.trim( $response.html() ).length ) { $response.html( '' ); } $.ajax({ type: $form.attr('method'), //You should use type if you're using versions of jQuery prior to 1.9.0. dataType: 'json', url: js_obj.admin_ajax, data: $form.serialize(), }).always(function (data) { var $status = ( typeof data.status !== 'undefined' ) ? data.status : 'danger'; var $message = ( typeof data.message !== 'undefined' ) ? data.message : js_obj.text_error; var $message_html = ''; var $data_html = ( typeof data.html !== 'undefined' ) ? data.html : ''; if($target) { $($target).html( $data_html ); } else { $response.html( $message_html ); } if( typeof data.redirect !== 'undefined' ) { //setTimeout( function() { parent.location.href = data.redirect; //}, 1000 ); } else if( typeof data.reload !== 'undefined' ) { window.location.reload( true ); } $btn.button('reset'); }); } });