mvasco mvasco - 4 months ago 22
Ajax Question

Getting JSON array elements values

I want to show data received from a remote JSON source on a HTML table.

This is part of the script I am using now

var loadData = function(){
$.ajax({
type:"POST",
url:"http://......"
}).done(function(data){
console.log(data);
var users = JSON.parse(data);
for(var i in users){
$("#content").append("<td>"+users[ i ]+"</td>");
}
});


The console shows following output:

{"data":[["1","PMI-M-072"]]}


On the first td tag appear 1,PMI-M-072 as value.
But I need to show each array element on a td tag.
How can I get each element value?

Answer

I think you'll want to do:

var users = JSON.parse(data)["data"];

instead of:

var users = JSON.parse(data);