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

124
Vistas
Javascript check in array if string is found not working with indexOf

I use the function spawnList to insert content into a html-table. In my console.log(items[i].Name); I get strings like Sense. But in my second JQuery-Ajax call to getVotesList.php I got the error cannot read properties of undefined (reading 'Name'). I want to search the string from the first ajax-call in the array from the second ajax-call. But because it cannot read items[i].Name .

Is there a way I can give the variable to the subajaxcall?

function spawnList(sort) {
  $.get("./includes/liveSearch.php", function(data, status) {
    var items = JSON.parse(data);
    for (var i = 0; i < items.length; i++) {
      console.log(items[i].Name);
      var name = '<?php echo $_SESSION['user_info']['first_name']; ?>';
      $.post("./includes/getVotesList.php", {
        name: name
      }, function(result) {
        var list = JSON.parse(result);
        if (list.indexOf(items[i].Name) > -1) {
          console.log('y');
        } else {
          console.log('n');
        }
      });
    }
  });
}
spawnList();
about 4 years ago · Juan Pablo Isaza
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