a = false;

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

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

    if (category_name == "") {
        showProAlert('error', 'Error', 'Please Enter Required Fields');
        return;
    }

    if (id > 0) {
        a = true;
        var formData = new FormData($("#Form")[0]);
        $.ajax({
            url: base_path + "category/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 + "category/index";
                });
            }
        });
    }else {
    var formData = new FormData($("#Form")[0]);

    $.ajax({
        url: base_path + "category/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 (response) {
            $("#Form")[0].reset();

            showProAlert('success', 'Success', 'Data Submitted Successfully').then(function () {
                window.location.href = base_path + "category";
            });
        }
    });
}
}
