reorx
5/29/2014 - 6:12 AM

ajax_form.js

// Hijack form submit event, make ajax call according to the form's attributes
// and data, then reload the page directly after success.
$.fn.reload_after_submit = function() {

    this.on('submit', function(e) {
        e.preventDefault();

        var form = $(this),
            url = form.attr('action'),
            type = form.attr('method') || 'POST',
            data = form.serialize();

        // Disable submit button
        form.find('[type=submit]').attr('disabled', 'disabled');

        $.ajax({
            url: url,
            type: type,
            data: data,
            success : function(){
                //console.log('success');
                humane_log('Success!', 'success', function() {
                    window.location.reload();
                });
            }
        });
    });
};

window.humane_log = humane_log = function(message, type, callback) {
    type = type || 'success';
    humane.log(
        message,
        {addnCls: 'humane-flatty-' + type, timeout: 1500},
        callback);
};