I have a ajax returning json array data like this,
[{
"UserName": "John",
"Total": "45",
"Correct(%)": "71.1111",
"Incorrect(%)": "28.8889"
}, {
"UserName": "KKK",
"Total": "42",
"Correct(%)": "47.6190",
"Incorrect(%)": "52.3810"
}, {
"UserName": "AAA",
"Total": "54",
"Correct(%)": "81.4815",
"Incorrect(%)": "18.5185"
}, {
"UserName": "BBB",
"Total": "39",
"Correct(%)": "58.9744",
"Incorrect(%)": "41.0256"
}]
I want to show that data by using javascript like this,
UserName: John Total: 45 Correct(%): 71.1111
Incorrect(%): 28.8889UserName: KKK Total: 42 Correct(%): 47.6190
Incorrect(%): 52.3810UserName: AAA Total: 54 Correct(%): 81.4815
Incorrect(%): 18.5185UserName: BBB Total: 39 Correct(%): 58.9744
Incorrect(%): 41.0256
So, I try like this,
$.ajax({
url: 'some.php',
type: 'post',
data: {dept:d},
dataType: 'json',
success: function(data) {
console.log("success");
var temp = "";
if(data && data!="") {
for(var i=0; i<data.length; i++) {
$.each(data,function(k,v){
$.each(v,function(k,s){
temp +=k+': <b>'+s+'</b>       ';
});
temp +="<br/><br/>";
console.log(temp);
});
}
document.getElementById('user').innerHTML= temp;
}
});
But, I got five line for each user. I was wrong while looping. So, how can I do this?
for loop