I have called rest api through ajax, i get the response from api in json format, now i want to display the data on my webpage. I want to show as follows
scheduled
driver_count:
passenger_count:
active
driver_count:
passenger_count:
My code as follows
$(document).ready(function() {
$.ajax({
asyn: true,
crossDomain: true,
url: "http://10.26.32.11/api/rating-service/rate/current/gettrips",
dataType: 'JSON',
callback: 'callback',
type: 'GET',
success: function(data) {
var jso = parseJSON(data);
console.log(jso);
}
});
});
JSON reply
{
"scheduled": {
"driver_count": 1,
"passenger_count": 1
},
"active": {
"driver_count": 0,
"passenger_count": 0
}
}
if you did not make this api by yourself, you can loop object by
but if you can edit api output script, this structure will make life easier:
You can access your variables as per below
Here:
You can create new variable as key_count with value and use that variable
Output