-1

Hello stackoverflow community, I need help with ajax $.get function. When I recieve array from getlist.php and i alert ir like this alert(data_list); everything works correctly. But when I try to alert like this alert(data_list.id) it doesn't work. Here is how my array looks like in console:

[{"id":"2","name":"Something","type":"horizontal","clicks":"0","start_date":"01/20/2016","end_date" :"02/19/2016","status":"1","target":"http://","image_url":"http://","pre_exp_email":"0"},{"id" :"1","name":"None","type":"horizontal","clicks":"2","start_date":"01/20/2016","end_date":"05/19/2016" ,"status":"1","target":"http://wps.us.lt","image_url":"http://....../wp-content/uploads/2016 /01/250by250ad.jpg","pre_exp_email":"0","group_id":["1"],"slots":{"1":"1"}}]

And here is myfunction which calls get function.

    function get_list() {
        jQuery.get("/wp-content/plugins/wp125/functions/getlist.php", { grouptype:jQuery('#grouptype').val() }, function(data_list){
            var str;
            alert(data_list.name);
        });             
    }
Sidas
  • 81
  • 1
  • 10

1 Answers1

0

If data is only a object like

var k={"id":123;"name":"abc"}

you can access id using k.id

but when it is object of Array like

var k=[{"id":123,"name":"abc"},{"id":13,"name":"ab"}];

in that case you have iterate over array something like this

for(i=0;i<k.length;i++)
    {console.log(k[i].id)}
Roli Agrawal
  • 2,356
  • 3
  • 23
  • 28