TECNOLOBO

No recuerdas tu codigo?
Se te olvido como se hace?

Aqui podras guardar lo que necesiten
Y cuando sea necesesario

Creado por julian gomez
iiiiii

estructura javascript ajax communityfunctions



Descripcion

estructura de trabajo

javascript


var communityFunctions = {
    token: $('meta[name="csrf-token"]').attr('content'),
    thisBaseUrl: window.location.protocol + '//' + window.location.host,
    baseUrlValida: 'http://172.17.3.118',
    basePortValida: '8080',
    dataGET: function getQueryVariable() {
        //window.location.search = 'hi';
        var urlStr = window.location.search.substring(1);
        var keysValue = urlStr.split('&');
        var get_vars = {};
        //console.log(keysValue);
        if (!keysValue[0] && keysValue.length == 1) return get_vars;
        for (var i = 0; i < keysValue.length; i++) {
            var objUri = keysValue[i].split('=');
            Object.defineProperty(get_vars, objUri[0], {
                value: objUri[1],
                writable: true,
                enumerable: true,
                configurable: true
            });
        }
        keysValue.forEach(function(element, index, arr) {
            console.log('index => ' + index, 'element => ' + element);
        });
        return get_vars;
    },
    showCapeLoading: function() {
        this.cantProcessActives++;
        //console.log($('div#capeLoading'));
        $('div#capeLoading').removeClass('hide').show();
    },
    hideCape: function() {
        communityFunctions.cantProcessActives--;
        setTimeout(function() {
            console.log(communityFunctions.cantProcessActives);
            if (communityFunctions.cantProcessActives == 0) {
                $('#capeLoading').hide();
            }
        }, 300);
    },
    cantProcessActives: 0,
    executeAjax: function(urlParam, typeParam, dataParam, successFunction) {
        var objParamsAjax = {
            statusCode: {
                404: function() {
                    console.log("404 page not found");
                },
                500: function() {
                    console.log("500 Error in server");
                }
            },
            headers: {
                'X-CSRF-TOKEN': this.token,
                //'Content-Type': 'aplication/json'
            },
            type: 'POST',
            crossDomain: true,
            dataType: 'json',
            url: urlParam,
            data: dataParam,
            success: function(result) {
                //console.log(result);
                if (result.session == false) {
                    alert(result.mensaje);
                    return;
                }
                successFunction(result);
            },
            error: function(req, status, err) {
                console.log('Error: ', req);
                //communityFunctions.executeErrorMessage(err);
            },
            beforeSend: function() {
                this.cantProcessActives++;
                $('div#capeLoading').show();
            },
            complete: function() {
                setTimeout(function() {
                    this.cantProcessActives--;
                    if (this.cantProcessActives == 0) {
                        $('div#capeLoading').hide();
                    }
                }, 3000);
            }
        };
        $.ajax(objParamsAjax);
    },
    executeErrorMessage: function(err) {
        console.log(err);
    },
    borrarHistorial: function() {
        //history.pushState(null, null, document.URL);
        /*window.addEventListener('popstate', function() {
            history.pushState(null, null, document.URL);
        });*/
    },
    bloquearRegreso: function() {
        //window.history.forward();
        //window.location.hash = "no-back-button";
        //window.location.hash = "Again-No-back-button"; //chrome
        /*window.onhashchange = function() {
            window.location.hash = "no-back-button";
        };*/
        //history.replace(history.forward(1));
    }
};