I have some values that are returned to ajax from backend. The problem in this code is that when I do console.log(myRows) the values in cells are undefined.
$(document).on('click', ".myButton", function () {
$.ajax({
type: "POST",
url: "Administration.aspx/GetMyCollection",
data: JSON.stringify({ 'Parameter': Parameter }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
var myRows = "";
$.each(data, function (i, values) {
values.ObjectID;
values.ObjectName;
values.ObjectValue;
values.Object;
console.log(values);
myRows += "<tr><td>" + values[1].ID + "</td><td>" + values[1].ObjectName + "</td><td>" + values[1].ObjectValue + "</td><td>" + values[1].Object + "</td></tr>";
console.log(myRows);
});
}
console.log("Saved!");
},
error: function () {
console.log("Not Saved!");
}
});
});
But when I change the code and add values[1], the values are displayed correctly.
myRows += "<tr><td>" + values[1].ID + "</td><td>" + values[1].ObjectName + "</td><td>" + values[1].ObjectValue + "</td><td>" + values[1].Object + "</td></tr>";
I need help to change the code so it will loop through all 9 (from 1 to 9) values and places the results in myRows cells so all the values can be displayed.
Json code:
d […]
0 {…}
ObjectID 1
ObjectName Vegas
ObjectValue 234
Object Arizona
1 {…}
ObjectID 2
ObjectName Chicago
ObjectValue 211
Object Montana
2 {…}
ObjectID 3
ObjectName Livepool
ObjectValue 123
Object London
...
Thanks in advance !