Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
Use Ajax response to skip a loop iteration in Jquery

I am trying to skip a loop iteration based on the ajax response. The problem I'm facing is that I'm unable to use the response from Ajax outside the Ajax call. Currently I solved it by using the below solution but here the problem is that I'm using async: false which is not recommended as Ajax call is async.

function ajaxCallHere(name) {
    let url = '/admin/someUrl/' + name;
    var skipName = '';
    $.ajax({
        'url': url,
        'type': 'GET',
        async: false,
        'success': function (data) {
            skipName = data.skip;
        }
    });
    return skipName;
}

function getAllNames() {
    for (let i = 0; i < names.length; i++) {
        var skipVal = ajaxCallHere(names.fullName);

        if(skipVal == 'yes') {
            continue;
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use async/await, since $.ajax returns an object that obeys the Promise protocol.

function ajaxCallHere(name) {
  let url = '/admin/someUrl/' + name;
  return $.get(url);
}

async function getAllNames() {
  for (let i = 0; i < names.length; i++) {
    var data = await ajaxCallHere(names.fullName);
    if (data.skipVal == 'yes') {
      continue;
    }
  }
}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda