How to execute a function, after having obtained a server value, jquery?

0

Good morning. I have the following function where it returns the value idPedido

function obtenerPedido() {
     axios.get('https://URL/Pedido?CodigoCliente=${codclienteAfiliadoPedido}&Cod_Trib=${cod_trib}&TipoSocio=${idtiposocio}', {
                    headers: {
                        Authorization: token_type + " " + access_token
                    }
                }).then(function (response) {
                    myApp.showIndicator();
                    console.log(response);
                    localStorage.setItem("IDPedido", response.data.IDPedido);
                    idPedido = localStorage.getItem("IDPedido");//Aca guardo el id del pedido.
                    myApp.hideIndicator();
                }).catch(function (error) {
                    console.log(error);
                    myApp.hideIndicator();
                });
}

The detail arises that before the previous function obtains the requested id, this other function is executed and the problem is that for this function to run correctly, it needs the requested id parameter:

function listarPedido() {
    idPedido = localStorage.getItem("IDPedido");
        axios({
        method: 'GET',
        url: 'https://URL/AppListaPedido?IDPedido=${idPedido}&TipoEnvio=${TipoEnvio}&Cod_Agencia=${cod_agencia}&Cod_depto=${cod_depto}&ProductoGratis=${ProductoGratis}&EquipoSocioNuevo=${EquipoSocioNuevo}&Cod_cliente=${cod_cliente}',
        headers: {
            Authorization: token_type + " " + access_token
        }
        })
            .then(function (response) {
                console.log(response);                
            }).catch(function (error) {
                console.log(error);
                myApp.hideIndicator();
            });
}

For this situation I do not want to have the function listarPedido() within the function obtenerPedido()

Thank you very much.

    
asked by JG_GJ 27.09.2018 в 18:06
source

0 answers