function formAction(elem)
{
    event.preventDefault();
    var action = $(elem).attr('action');
    var method = $(elem).attr('method');
    $(elem).find(':submit').prop('disabled', true);
    if(method == 'GET')
    {
        var dataform = $(elem).serialize();
    }
    else
    {
        var dataform = new FormData( $(elem)[0]);
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
    }

    $.ajax
    ({
        url : action,
        type: method,
        data: dataform,
        dataType:'json',
        contentType: false,
        processData: false,
        success:function(data)
        {
            $(elem).find(':submit').removeAttr('disabled');
            if('data' in data)
            {
                toasterSuccess(data.message);
                setTimeout(
                    function()
                    {
                        window.location.href = data.data
                    }, 1000);
            }
            else
            {
                if (typeof data.errors == 'object')
                {
                    toasterError(Object.values(data.errors)[0]);
                }
                else
                {
                    toasterError(data.errors);
                }
            }
        }
        ,error:function(data)
        {
            $(elem).find(':submit').removeAttr('disabled');
            if (typeof data.responseJSON.errors == 'object')
            {
                toasterError(Object.values(data.responseJSON.errors)[0]);
            }
            else
            {
                toasterError(data.responseJSON.errors);
            }
        }
    })
}


