.each() not returning data
I have the jQuery function below that is not returning the data back to my table. This line:
- window.alert("Userlist: " + JSON.stringify(usersList));
returns the data but this line:
- row = $('<tr id="row-' + item.id + '"><td>' + item.FullName + '</td></tr>');
is not returning the item.id and item.FullName. Ideas??$.each()
- $(function () {
- var usersList = [];
- function init() {
- $.ajax({
- url: '@Url.Action("GetNames", "UserNames")',
- type: "GET",
- dataType: "json",
- cache: false,
- async: true,
- success: function (data) {
- var row = null,
- first = true,
- timer = null;
- // populate local users list:
-
- usersList = data;
- window.alert("Userlist: " + JSON.stringify(usersList));
- // populate HTML for table:
- $.each(usersList, function () {
- $.each(this, function (index, item) {
- row = $('<tr id="row-' + item.id + '"><td>' + item.FullName + '</td></tr>');
- // row = $('<tr id="row-' + item.Id + '"><td>' + item.FullName + '</td></tr>');
- window.alert("row: " + row);
- // add a timer to the first row:
- if (first) {
- $(row).append(getTimer());
- $(row).append("<td>" + "<button id='pauseButton'>Pause</button>" + "</td>");
- first = false;
- }
- $('#NameList').append(row);
- });
- });
- },
- error: function (error) {
- console.log(error);
- }
- });
- }
- init();