Reputation: 95
I'm new to jquery and a I've got the problem as mentioned in the title. My controller code looks like:
[HttpPost]
public JsonResult getProjectList()
{
List<Project> projectList = new List<Project>();
foreach (IML.ProjectInfo pr in getProjectArray())
{
Project x = new Project(pr.Name, pr.ID, pr.OwnerID, pr.CreatedBy, pr.CreatedAt, "", pr.Deleted, pr.Closed);
projectList.Add(x);
}
return Json(projectList.ToArray());
}
When I check the projectList under debugger mode it has 6 elements. In my webpage I have the following ajax call:
$.ajax({
url: '@Url.Action("getProjectList")',
type: "POST",
//enumerowanie projektów
success: function (data) {
projekty = data;
var wyswietl ="<table><tbody>";
var tabelka = "";
var wybranyProjekt;
alert($.data.length);//this alert tells me that data.length is 3
for (i = 0; i < 6; i++)//even if $.data.length is 3 the data[i].Name holds values for 6 elements
{
tabelka += "<tr class=\"enumeracjaProj\" id=\"" + i
+ "\"><td class=\"projekty\" id=\"" + i + "\"> " + data[i].Name + " </td></tr>"
}
wyswietl += tabelka;
wyswietl += "</tbody></table>";
$('#projekty_div').append(wyswietl);
})
Even if I Post an array of 6 elements ajax result tell me that its length is 3. If I go over it in loop which was 6 iterations hard-coded I get properly displayed name.
Upvotes: 0
Views: 105
Reputation: 3720
Small correction, You should change your alert($.data.length);
to alert(data.length);
$.data
is jQuery function and your data
is response result
Upvotes: 1