When I pass an php array to jquery
$testArr = array('a','b','c');
echo json_encode($testArr);
Jquery script
$.post(
"http://localhost/xiuno",
{useranswers:arr,shijuanid:shijuanid},
function(data){
alert(data[0]);
}
It shows nothing,so,how to access data by using index?
Also there's one thing confused me, I changed alert(data[0]);
to alert(data);
it shows ["a","b","c"]
, it is neither a JSON type like ["0":"a","1":"b","2":"c"]
or an array, cause it can not be accessed by index,so, what exactly is the data retrieved from PHP script? It was supposed to be JSON, but not.
Also,I'm wondering is there a way to pass array directly from PHP, the following code does not work
$testArr = array('a','b','c');
echo $testArr;
Because an array can not be echoed, so how to do it?