php - Duplicate entries appending from json object -
i have searched stackoverflow , implemented next jquery code, json object php , append li tags, appending 3 instances of 1 value. sample code is:
var $childs = $('.childs'); $.getjson('common/db/fetchuniversity.php', function(data) { $(data).each(function() { var $element = $childs.clone().removeclass('childs').appendto('#colleges'); $element.attr('id', this.id+"u"); $element.html("<a href='#' class='img'><strong><img alt='image' src='images/mit.jpg' style='height:40px; width:40px;' /></strong></a><div style='padding-right: 30px;'><h4 style='display:inline; margin:1px;'>"+this.name+"</h4><p style='display:inline;'>"+this.description+"</p></div><p style='margin:2px;'><a href='#' style='text-decoration: none;'><span class='ui-icon ui-icon-circle-plus' style='display:inline-block; vertical-align:middle;'></span>follow</a></p><ul class='actions'><li class='remove'><a href='javascript:removeme('#"+this.id+"u')'><span class='ui-icon ui-icon-closethick'>close</span></a></li></ul>"); }); }); $.getjson('common/db/fetchpeople.php', function(data1) { $(data1).each(function() { var $element = $childs.clone().removeclass('childs').appendto('#people'); $element.attr('id', this.id+"p"); $element.html("<a href='#' class='img'><strong><img alt='image' src='"+btoa(this.pic)+"' style='height:40px; width:40px;' /></strong></a><div style='padding-right: 30px;'><h4 style='display:inline; margin:1px;'>"+this.name+"</h4><p style='display:inline;'>"+this.job_desc+","+this.location+"</p></div><p style='margin:2px;'><a href='#' style='text-decoration: none;'><span class='ui-icon ui-icon-circle-plus' style='display:inline-block; vertical-align:middle;'></span>follow</a></p><ul class='actions'><li class='remove'><a href='javascript:removeme('#"+this.id+"p')'><span class='ui-icon ui-icon-closethick'>close</span></a></li></ul>"); }); }); $.getjson('common/db/fetchgroups.php', function(data) { $(data2).each(function() { var $element = $childs.clone().removeclass('childs').appendto('#groups'); $element.attr('id', this.id+"g"); $element.html("<a href='#' class='img'><strong><img alt='image' src='images/groups/hbr.jpg' style='height:40px; width:40px;' /></strong></a><div style='padding-right: 30px;'><h4 style='display:inline; margin:1px;'>"+this.name+"</h4><p style='display:inline;'>"+this.job_desc+","+this.location+"</p></div><p style='margin:2px;'><a href='#' style='text-decoration: none;'><span class='ui-icon ui-icon-circle-plus' style='display:inline-block; vertical-align:middle;'></span>follow</a></p><ul class='actions'><li class='remove'><a href='javascript:removeme('#"+this.id+"g')'><span class='ui-icon ui-icon-closethick'>close</span></a></li></ul>"); }); });
the above code fetching 3 json objects, , appending li tags, above adding 3 instances of single value. li tags within of jquery accordion.
when nail json php file, returning correct, guess jquery code doing wrong me. please allow me know going wrong.
json object, when entered in browser:-
[{"id":1,"name":"stanford university","description":"one of best university in world"},{"id":2,"name":"princeton university","description":"one of best university in world"},{"id":3,"name":"yale university","description":"one of best university in world"},{"id":4,"name":"california university","description":"one of best university in world"},{"id":5,"name":"yale university","description":"one of best university in world"},{"id":6,"name":"california university","description":"one of best university in world"},{"id":7,"name":"princeton university","description":"one of best university in world"},{"id":8,"name":"stanford university","description":"one of best university in world"},{"id":9,"name":"california university","description":"one of best university in world"},{"id":10,"name":"princeton university","description":"one of best university in world"},{"id":11,"name":"yale university","description":"one of best university in world"}]
the above id:1 values appending 3 times, happening values.
maybe there more 1 elements class childs in dom.
php jquery json
No comments:
Post a Comment