1

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];
1
  • Very vague, you need to add more detail in order for anyone to answer this question. Commented Feb 28, 2011 at 23:54

1 Answer 1

3

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));
Sign up to request clarification or add additional context in comments.

2 Comments

Based on the question I think this is the best answer.
and the string should be: '{"x1":12, "x2":32, "x3":0}'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.