Reputation: 9185
I'm building a nice app with CodeIgniter and Ajax JQuery which returns finally a nice JSON like object looking like the following out of the success function via console.log ()
:
var data2 = {"field":fieldname,
"pagetitle":userdata};
$.ajax({
type: "POST",
url: "getdata_ajax",
dataType: 'json',
data: data2,
success: function(data) {
console.log(data);
}
});
The result of the success function:
Since quite a while I'm trying to get just one value out of that object. I tried
console.log (data.id)
console.log (data[id])
but nothing worked. I'm sure its just a stupid thing. Any help?
Upvotes: 2
Views: 19198
Reputation: 1491
The data object seems to be an array to you have to use something like console.log(data[0].id)
.
Upvotes: 1
Reputation: 1902
data is an array in this case so use an index to get the first object:
data[0].id
Upvotes: 10