Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!