Home Yii2: How to get an array object using Ajax?
Reply: 0

Yii2: How to get an array object using Ajax?

user848
1#
user848 Published in June 21, 2018, 6:28 am

I am using Yii2 framework for almost a year and now it's the first time I have to use Ajax with an array. I have a this Ajax request:

$.post("/laboratorio/analitos-grupos/analitos-grupos", json)
    .done(function(data) {
        console.log("Data Loaded: " + data);
        console.log("First object: " + data[0]);       
    });

But the console shows:

Data Loaded: [{"id":6,"color":"Blue"},{"id":4,"color":"Brown"},{"id":12,"color":"Red"}]
First object: [

I think it should shows:

Data Loaded: [{"id":6,"color":"Blue"},{"id":4,"color":"Brown"},{"id":12,"color":"Red"}]
First object: {"id":6,"color":"Blue"}

How can I get the first object? Is jQuery the best way to use Ajax in Yii2? I can't find a complete example on Google.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310229 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO