Make an ajax request if another ajax request was successful

1

How can I do so that when an AJAX response enters into the success, execute another ajax method?

Currently I only run the most external AJAX method and the AJAX more internal does not execute it, this is my AJAX code.

$.ajax({
type: 'POST',
url: 'guardarFactura',
data: {
  "factura": varFactura,
  "nombre": varNombre,
  "apellidop": varApellidop,
  "apellidom": varApellidom,
  "fechaAlm": varFechaAlm,
  "fechacel": varFechaTel,
  "emailUsuario": varEmailu
},
success: function(resultado) {
  cargando.hide();

  $('#grillaArticulo tbody tr').each(function() {

    var fac = $(this).find("td").eq(0).html();
    var cant = $(this).find("td").eq(1).html();
    var marc = $(this).find("td").eq(2).html();
    var mod = $(this).find("td").eq(3).html();

    $.ajax({
      type: 'POST',
      url: 'guardarArticulo',
      data: {
        "factura": fac,
        "cantidad": cant,
        "articulo": marc + " " + mod
      },
      success: function(resultado) {
        console.log("ARTICULO: " + resultado)
      }

    });
  });

  $('#grillaSIM tbody tr').each(function() {

    var fac = $(this).find("td").eq(0).html();
    var cant = $(this).find("td").eq(1).html();
    var marc = $(this).find("td").eq(2).html();

    $.ajax({
      type: 'POST',
      url: 'guardarSim',
      data: {
        "factura": fac,
        "cantidad": cant,
        "articulo": marc
      },
      success: function(resultado) {
        console.log("SIM: " + resultado)

      }

    });
  });

  alert(resultado);
  event.preventDefault();

},
error: function(jqXHR, textStatus, errorThrown) {

  if (jqXHR.status === 0) {

    alert('Not connect: Verify Network.');

  } else if (jqXHR.status == 404) {

    alert('Requested page not found [404].');

  } else if (jqXHR.status == 500) {

    alert('Error Interno del Servidor [500].');

  } else if (textStatus === 'parsererror') {

    alert('Requested JSON parse failed.');

  } else if (textStatus === 'timeout') {

    alert('Time out error.');

  } else if (textStatus === 'abort') {

    alert('Ajax request aborted.');

  } else {

    alert('Uncaught Error: ' + jqXHR.responseText);

  }

}
});
    
asked by Ivxn 14.06.2016 в 18:50
source

1 answer

0

You should have no problem when calling yourself in the success, probably on the server side, sending the error to ajax, I recommend adding the 'error' to the internal call to rule out a problem in it, discarding this possibility another Possible error is that something is wrong in any of the each that you manage in the success and you never send your second ajax call just debugging you could know it.

I hope I can help, greetings.

    
answered by 15.06.2016 в 03:46