T
T
tigra2015-09-25 16:02:14
JavaScript
tigra, 2015-09-25 16:02:14

How to put an object into an array?

A selection is made from the table by key,
$query = Calendar::model()->findByPk($id);
then we need to send it all with AJAX.
echo CJSON::encode($query);
There I get such an unknown garbage:

{id: "17", id_name: "20", date: "2015-09-25", address: "В офисе", company: "1234567", timestart: "",…}
       address: "В офисе"
       company: "1234567"
       date: "2015-09-25"
       id: "17"
       id_name: "20"
       office: "1"
       other_info: "test"
       timeend: "11:10"
       timestart: "12:20"

I can't access any element of the object(data.date, data["date"]), so I want to cast this object to an array before passing AJAX

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2015-09-25
@tigroid3

Oh well, try this:

var dataObj = JSON.parse(data);
console.log(dataObj.id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question