I am trying to figure out how to sort my list of usernames in alphabetical order. Here is the code I have been working on, but it doesn't seem to be functioning properly. I have made some edits to the code.
script.js:
function displayUsers() {
$("#mySecond").empty();
var x = document.getElementById("mySelect").value;
$.ajax({
url: "https://cubber.zendesk.com/api/v2/organizations/"+x+"/users.json",
type: 'GET',
dataType: 'json',
cors: true ,
contentType:'application/json',
secure: true,
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1c2cdc0c8d3c48fd1c0c6cfc8c4dbe1c2d4c3c3c4d38fc2cecc">[email protected]</a>:CC..11cc"));
},
success: function (data){
for (i = 0; i < data.users.length; i++) {
var username = data.users;
data.users.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
var userId = data.users[i].id;
var allData = data.users[i];
console.log(allData);
$("#mySecond").append('<option value="'+ userId +'">'+ username +'</option>')
}
},
});
}