a = false;

$(document).ready(function () {
    $("#btn_savee").click(function () {
        if (a == false) {
            saveperform();
        }
    });
});

function saveperform() {
    var id = $('#id').val();

    if (id > 0) {
        a = true;
        var formData = new FormData($("#Form")[0]);
        $.ajax({
            url: base_path + "unit/updatedata",
            type: "POST",
            data: formData,
            processData: false,
            contentType: false,
            beforeSend: function () {
                $('#btn_savee').prop('disabled', true).html('<i class="fa fa-spinner"></i> Loading');
            },
            success: function () {
                $('#btn_savee').html('<i class="fa fa-check-circle"></i> Save').prop('disabled', false);
                showProAlert('success', 'Success', 'Data Updated Successfully').then(function () {
                    window.location.href = base_path + "unit/index";
                });
            }
        });
    } else {
        var formData = new FormData($("#Form")[0]);
        $.ajax({
            url: base_path + "unit/insert",
            type: "POST",
            data: formData,
            processData: false,
            contentType: false,
            beforeSend: function () {
                $('#btn_savee').prop('disabled', true).html('<i class="fa fa-spinner"></i> Loading');
            },
            success: function () {
                $("#Form")[0].reset();
                $('#btn_savee').html('<i class="fa fa-check-circle"></i> Save').prop('disabled', false);
                showProAlert('success', 'Success', 'Data Submitted Successfully').then(function () {
                    window.location.href = base_path + "unit/index";
                });
                a = false;
            }
        });
    }
}
