Monday, 15 June 2015

javascript - Jquery array.length is shorter than the real array length -



javascript - Jquery array.length is shorter than the real array length -

i'm new jquery , i've got problem mentioned in title. 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); } homecoming json(projectlist.toarray()); }

when check projectlist under debugger mode has 6 elements. in webpage have next 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 data.length 3 (i = 0; < 6; i++)//even if $.data.length 3 data[i].name holds values 6 elements { tabelka += "<tr class=\"enumeracjaproj\" id=\"" + + "\"><td class=\"projekty\" id=\"" + + "\"> " + data[i].name + " </td></tr>" } wyswietl += tabelka; wyswietl += "</tbody></table>"; $('#projekty_div').append(wyswietl);

})

even if post array of 6 elements ajax result tell me length 3. if go on in loop 6 iterations hard-coded displayed name.

small correction, should alter alert($.data.length); alert(data.length);

$.data jquery function , data response result

javascript jquery asp.net asp.net-mvc

No comments:

Post a Comment