Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get object value with Ajax request

Tags:

json

jquery

ajax

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

  • console.log (data.id)
  • console.log (data[id])
  • etc

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

like image 890
Jurudocs Avatar asked Jul 28 '26 06:07

Jurudocs


1 Answers

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

data[0].id
like image 159
Nathan Q Avatar answered Jul 29 '26 21:07

Nathan Q



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!