return a php associative array to javascript array
- by Eric Sim
I am trying to return a php associative array to javascript array through ajaxRequest.responseText
Here's what I do.
First in php, I do this:
$encoded = json_encode($thisarray);
echo $encoded;
If I echo $encoded, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"}
Then in js script,
thisarray = new Array();
thisarray = ajaxRequest.responseText;
If I alert thisarray, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"}
That's wrong since alerting an array should give error. But in this case, when I alert thisarray, I get the full array!!
Needless to say, I can't call my value out of thisarray, since it is yet defined as an array.
Anyone can tell me what am I missing here?