How to loop this array right from ajax?
How to read this array in ajax? Can you please look at this server response:
Array
(
[success] => 1
[0] => Array
(
[0] => Mr Green
[FirstName] => Mr Green
[1] => Hulk
[LastName] => Hulk
[2] => 30
[Age] => 30
)
[1] => Array
(
[0] => Mrs Green
[FirstName] => Mrs Green
[1] => Hulk
[LastName] => Hulk开发者_运维知识库
[2] => 28
[Age] => 28
)
)
And here's my ajax success
success: function(data){
if(data.success == true){
$("#output2").append("<p>"+ data.FirstName +"</p>");
}
}
How to loop this right? Thanks.
Try this:
if(data.success == true){
$.each(data,function(k,v){
if (typeof(v.FirstName) != "undefined"){
$("#output2").append("<p>"+ v.FirstName +"</p>");
}
});
}
精彩评论