i'm trying to update a listbox using ajax/jquery/webmethod. from inspecting network activity in developer tools in chrome, i can see that the webmethod is returning values, but those values are not being appended to the listbox. so i guess that the problem must be with my javascript code. could someone take a look at the code and tell me why this isn't working? the listbod is called ListBox1 and is in the Homepage.aspx page.
$(function updateListbox() {
var lBox = $('select[id$=ListBox1]');
setInterval(function () {
$.ajax({
beforeSend: function (req) {
req.setRequestHeader("Accept", "application/json");
},
type: "POST",
url: "Homepage.aspx/getCurrentList",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var results = data.d;
if (results.length > 0) {
var updatedList = [];
for (var i in results) {
updatedList.push(results[i]);
}
$(lBox).append(updatedList.join(''));
}
else alert("No new items to update...");
}
});
}, 5000);
});
[WebMethod()]
public static string[] getCurrentList()
{
int count = 0;
for(int i = 0; i < Global.ListUsers.Count(); i++)
count++;
string[] results = new string[count];
for (int i = 0; i < count; i++)
results[i] = Global.ListUsers[i].Username.ToString();
return results;
}