Crea tu propia función jQuery

by | Feb 28, 2019

Con jQuery.fn podras declarar funciones que se pueden usar al igual que las funciones de jQuery normales, en los elementos DOM!.

jQuery.fn.extend({
    ITValidaParte1: function () {
        var valor = $(this).val();
        var ret = true;
        this.each(function () {
            $.ajax({
                url: 'Man_Ajax.asp',
                type: 'POST',
                data: 'NP=' + valor + '&opcion=chkParte',
                async: false,
                beforeSend: function () { },
                success: function (response) {
                    if (response === '1') {
                        ret = true;
                    } else {
                        ret = false;
                    }
                },
                complete: function () {
                }
            });
        });
        return ret;
    }
});

Se utilizaría así:

if ( !$('#Parte').ITValidaParte1() ) {
     alert('Número No existe');
}else{
     alert('Número Existe');
}