JSFiddle - React, Tailwind, and code Playground

by Elkin Siabato

JavaScript

function llamarAjax(callback){
    $.ajax({
        type: 'POST',
        tryCount : 0,
        retryLimit : 3,
        url: 'ImpersonationCheckView.aspx',
        data: {
            'type': 'validateDocuments'
        },
        success: function (result) {
            return callback(result);
        },
        error: function (messageError) {
            this.tryCount++;
            if (this.tryCount <= this.retryLimit) {
                //try again
                $.ajax(this);
                return callback('-1');
            }            
            return callback('-2');
        }
    });
}
llamarAjax(function(retorno){
    alert('haber: ', retorno);
});