Page 1 of 1

Passing array from php to javascript using json_encode

Posted: Mon Sep 30, 2013 11:41 am
by samir_gambler
Hi,
I tried to pass an array to javascript from PHP using

Code: Select all

echo json_encode($arr_wrd);
Whine I try to access the data in JavaScript using

Code: Select all

xhr.responseText;
I get the output as

Code: Select all

["timekeeping","plover","instability","memorabilia","semidark"]
I want to treat each element as array. can anyone please help me how to do that.

Thanks & Regards,
Samir

Re: Passing array from php to javascript using json_encode

Posted: Mon Sep 30, 2013 12:40 pm
by AbraCadaver
That is a json encoded array. You need to decode it in the javascript.

Re: Passing array from php to javascript using json_encode

Posted: Mon Sep 30, 2013 9:16 pm
by samir_gambler
Thanks I was able to get the object using JSON.parse(xhr.responseText)