2

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();
Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0