Reputation: 10400
I want to put the ajax response to a Javascript array.
For example
Server Side
$response = '{x1:12, x2:32, x3:0}'
echo $respons;
Client side
var arrayObject = [{x1:132, x2:332, x3:320}]
arrayobject += [ajaxResponse];
Upvotes: 1
Views: 1652
Reputation: 231
Use JSON.parse to convert the text to a real object and Array.push to add it to the array.
arrayobject.push(JSON.parse(ajaxResponse));
Upvotes: 3