javascript - Json data getting values issue -
i using jquery getjson method value json... next code that..
//var data_url="message.json"; var data_url="php/server_processing.php"; var count = 0;//will computed(no of entries in json file) var paginationcount=20; var i=0,j=0; var symflag=0; $(window).load(function () { $.getjson(data_url, function(data) { for(var key in data.data) { if(data.data.hasownproperty(key)) { count++; } } //alert("count:"+count); var output=""; //alert(data.data[0].short_desc); (i=0;i<paginationcount;i++) { //alert(data.data[i].title); var id=data.data[i].id; var title=data.data[i].title; var short_desc=data.data[i].short_desc; var created_by=data.data[i].created_by; var date=data.data[i].date; var time=data.data[i].time; output+="<div class='brick'><div class=mhead>" + id + " " + title + "</div><div class='mbody'>" + short_desc + "</div><div class='mfoot'>" + created_by+ " " + date+ " " + time+"<a data-toggle='modal' data-target='#mymodal' onclick='fillmodaldata(" +i+")'> more...</a></div></div>"; } $( "#freewall" ).append( output ); wall.fitwidth(); }); });
json input php file:
{"data":[ {"id":1,"category":"computer programming","title":"c","short_desc":"c","created_by":"ash","date":"03\/07\/2014","time":9}, {"id":2,"category":"web","title":"d","short_desc":"asdasdasd","created_by":"mad","date":"03\/07\/2014","time":1},{"id":3,"category":"ui","title":"b","short_desc":"dfvdfvfdv","created_by":"ron","date":"03\/07\/2014","time":2}]}
i usin freewall jquery plugin , trying messages dynamically json data. if "alert(data.data[i].title)"
desired output..but in @ "var id=data.data[i].id
", getting error data.data[i] undefined...
please help me resolve issue.. in advance
your loop problem.
for (i=0;i<paginationcount;i++) {
if there no 20 items in data.data array fail, instead safe thing is
for (var i=0, len = data.data.length;i<len;i++) {
you using static count paginationcount
loop counter value, if returned result not have paginationcount
number of items loop seek access elements out of bound resulting in returning undefined
javascript jquery json
No comments:
Post a Comment