Order wrong AjaxRequest

0

I am developing in EXTJS and when using an Ajax Request, there is always an order of code execution that hinders validations.

This is the problem:

An example, I call the parameters to the file save_avance.php.

Ext.Ajax.request({
    url: 'json/guardar_avance.php?accion=remuneracion',
    scope: this,
    params: {
        tipo_ingreso: form_nuevoContrato.getForm().findField('cmb_tipoUsuario').getValue(),
        mper_rut: form_nuevoContrato.getForm().findField('rut').getValue(),
        mper_dv: form_nuevoContrato.getForm().findField('dv').getValue(),
    },
    success: function (resp, request)
    {   var guardarRemuneracionOk = true;
        var respuestaremuneracion = Ext.util.JSON.decode(resp.responseText);

    }

if (guardarRemuneracionOk == true){

}

The problem is that the Ajax Request is executed, and when it reaches the success it does not enter it, but jumps to the code below, that is, to the IF, and then returns to the beginning of the Ajax Request, and at the end everything returns to success and if you enter it

This causes me problems when I need to execute code after the ajax, (for example the IF), which verifies me what happened with the variable saveRemunerationOk, but by skipping the success in the first execution, this IF is invalidated and does not serve me , since it does not know what happened with that variable when the success did not run first.

How can I fix that execution order so that the first run enters the succes and the IF can verify correctly?

thank you very much !!

    
asked by Camilo 09.11.2017 в 17:00
source

2 answers

0

The problem arises because the Ajax call is asynchronous.

add the async property with value to false async: false

Ext.Ajax.request({  
    async:false,  
    url: 'json/guardar_avance.php?accion=remuneracion',  
    scope: this,  
    params: {  
        tipo_ingreso:   form_nuevoContrato.getForm().findField('cmb_tipoUsuario').getValue(),  
        mper_rut: form_nuevoContrato.getForm().findField('rut').getValue(),  
        mper_dv: form_nuevoContrato.getForm().findField('dv').getValue(),  
    },  
    success: function (resp, request){  
        var guardarRemuneracionOk = true;  
        var respuestaremuneracion = Ext.util.JSON.decode(resp.responseText);  
    }
);  
if (guardarRemuneracionOk == true){}
    
answered by 24.01.2018 в 14:49
-1

Thanks to Cedano, what happens is that there are several Ajax correlatives, and each one should throw a true if it enters the success, and once all the ajax request is passed, there I verify if everyone threw me true or some remained in false, that's why I could not place the if inside the success, because they are several.

    
answered by 09.11.2017 в 19:18