I need to make 2 requests $.ajax()
nested, where the second depends on the delivered value of the first ... in other words the result of the first enters a loop and for each record found makes a new request
.
Something like this:
function mostrarInventarioOc() {
var urlPrincipal = $("#urlPrincipal").val(); // url base
var valor = $("#ocompra_id").val(); // id a buscar
$.ajax({
url: urlPrincipal+"detalle/buscarDetalleOC/"+valor+"/",
success:function(respuesta){
var detalle = eval(respuesta);
for (var i = 0; i < detalle.length; i++) {
$id = detalle[i]["id_pieza"]; // capturo id a buscar
$.ajax({
url: urlPrincipal+"bodega/stockBodega/"+id+"/",
success:function(result){
alert(result['cant_inventario']);
// aquí voy a imprimir los datos de la primera y segunda petición
}
});
}
}
});
}
I have read that this is much easier with promise javascript, but I have not managed to do it.