Jquery appending to add options in select attribute does not work

I need to sort through the JSON and for all the verified users add a option to the <select> attribute which has a id of verified-users-list.

The issue is that I am trying to append the results of the verified users to HTML

function getVerifiedUsers(id, url) {
  var ourRequest = new XMLHttpRequest();
  ourRequest.open('GET', url);
  ourRequest.onload = function() {
    var ourData = JSON.parse(ourRequest.responseText);
    let test = verified(ourData)
    //console.log(test);  
    $(id).append(`<option id: ${test.id}>${test.name}</option>`);
  }
  ourRequest.send();
}

function verified(data) {
  var user = {};
  var j = 0;
  for (let i = 0; i < data.length; i++) {
    if (data[i].verified == true) {
      user[j] = data[i];
      j++;
    }
  }
  return user
}

getVerifiedUsers("#verified-users-list", "http://localhost:3000/user");

AJAX response:

[{
    "id": 0,
    "name": "Yan Li",
    "verified": true
  },
  {
    "id": 1,
    "name": "Anna Lopez"
  },
  {
    "id": 2,
    "name": "Bobby Patel",
    "verified": true
  }
]

204 thoughts on “Jquery appending to add options in select attribute does not work”

  1. After I initially left a comment I seem to have clicked the
    -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get four
    emails with the exact same comment. There has to be a way you are able to remove
    me from that service? Kudos!

    Reply
  2. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the
    same niche. Your blog provided us beneficial information to work on. You
    have done a marvellous job!

    Reply
  3. Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is fundamental and all.
    However think of if you added some great visuals or video clips to give your posts more, “pop”!
    Your content is excellent but with pics and video clips, this website could definitely be
    one of the greatest in its field. Great blog!

    Reply
  4. My partner and I stumbled over here by a different page and thought I may as well check things out.
    I like what I see so now i’m following you. Look forward to
    finding out about your web page again.

    Reply

Leave a Comment