Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda