dedi wibisono dedi wibisono - 1 month ago 5x
Ajax Question

Can't rendering JSON to HTML by AJAX

I want to ask about JSON,
here is the JSON



And my JavaScript

var $content = $(".wrapper");
url : "//",
type : "GET",
dataType : "json",
success : function(data){
$.each(data, function(i, data){
$content.append("<div class='city'>"+ +"</div><div class='jumlah'>"+ data.count +"</div>");});

My HTML Page

<div class="wrapper">
<div class="city"></div>
<div class="jumlah"></div>

I want to show 'city and count' but the result is 'undefined undefined'. Anybody can help me? Thank you


Change this:

   $.each(data, function(i, data){

to this:

   $.each(, function(i, data){

The data variable that is the argument of your success function refers to the whole object, but what you actually seem to want to iterate over is that object's city property, which is an array of objects.