display array from multiple json objects with ajax & jquery -
i have multiple objects similar 1 below. want display mealreviews: [] array multiple json objects $('#mealdetails').html().
{ "_id": { "$oid": "59ef162f7afc7636" }, "mealida": "act", "mealidb": "tmnt2", "title": "teenage mutant ninja turtles 2 secret of ooze", "description": "the teenage mutant ninja turtles (mark caso, michelan sisti, leif tilden, kenn troum) again battle archenemy, rogue ninja shredder (francois chau). shredder attempts revenge obtaining same radioactive ooze created turtles , unleashing 2 new monstrous mutants: tokka, oversized snapping turtle, , rahzar, fearsome wolf-like creature. when shredder plans use remaining ooze on himself, turtles must harness ninja fighting skills stop him.", "releasedate": "march 22, 1991", "language": "english", "subtitle": false, "srt": "teenage mutant ninja turtles ii secret of ooze.srt", "director": "michael pressman", "actors": "paige turco \"april o'neil\", vanilla ice, michelan sisti \"michelangelo, soho man\", robbie rist \"michelangelo\", kevin clash \"splinter\"", "studio": "golden harvest company, new line cinema, northshore investments ltd.", "hrs": 1, "mins": 28, "ratings": "pg \u2013 parents cautioned", "dateadded": "2017-07-18t20:59:17.473z", "mealreviews": [ { "username": "dwaynekshrn", "accounttype": "cop", "subject": "lucky award winners", "rating": "1", "review": "i think movies deserves academy award", "reviewdate": "2017-07-25t23:29:53.371z" }, { "username": "dwaynekshrn", "accounttype": "cop", "subject": "one on shot clock", "rating": "1", "review": "he shoots, scores!", "reviewdate": "2017-07-24t22:58:17.622z" }, { "username": "shaolinkyle", "accounttype": "monk", "subject": "in da house", "rating": "1", "review": "shaolin kyle in house!", "reviewdate": "2017-07-24t22:47:56.056z" }, { "username": "dwaynekshrn", "accounttype": "cop", "subject": "political spectrum", "rating": "1", "review": "is dope son!", "reviewdate": "2017-07-24t22:51:51.106z" } ] }
i retrieving data ajax request doesn't seem returning data when check console.log. works when target specific object when try same data objects, i'm drawing blank.
$.ajax({ url: url, type: 'get', contenttype: "application/json; charset=utf-8", datatype: "json", success: function(data){ $('#mealdetails').empty(); // test see if retrieving data console.log(data.title); var reviews = []; var output = '<div>'; $.each(data.mealreviews, function(key, value) { output += '<div class="row">'; output += '<div class="col-sm-3 col-sm-offset-1 col-md-3 col-md- offset-1"><img class="img-thumbnail" src="images/' + this.accounttype +'.png" width="200" height="200" alt="">'; output += '<p>by <a>'+ this.username +'</a> '+ this.reviewdate +'</p></div>'; output += '<div class="col-sm-8 col-md-8"><div class="row">'; output += '<h2>'+ this.rating +'<span class="glyphicon glyphicon-star"></span> '+ this.subject +'</h2>'; output += '<p class="textformat">'+ this.review +'</p></div></div>'; output += '</div>'; }); output += '</div>'; reviews.push(output); $('#mealdetails').html(output); }, error:function(xhr,status,err){ console.log('nah bruh thats no go'); } });
replace
this.accounttype
value.accounttype
.
means have replace this.
value.
inside $.each(....)
Comments
Post a Comment