Jurudocs
Jurudocs

Reputation: 9185

Get object value with Ajax request

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:

enter image description here

Since quite a while I'm trying to get just one value out of that object. I tried

but nothing worked. I'm sure its just a stupid thing. Any help?

Upvotes: 2

Views: 19198

Answers (3)

TimPetricola
TimPetricola

Reputation: 1491

The data object seems to be an array to you have to use something like console.log(data[0].id).

Upvotes: 1

NimChimpsky
NimChimpsky

Reputation: 47310

data[0].id

min chars min chars

Upvotes: 1

Nathan Q
Nathan Q

Reputation: 1902

data is an array in this case so use an index to get the first object:

data[0].id

Upvotes: 10

Related Questions