In your PHP file, use json_encode to turn the array into a more convenient format for use in Javascript. This way you will have something like:
echo json_encode($myArray);
Then, in your JavaScript, the data variable of the success method will contain JSON. Use jQuery parseJSON to convert this to a JavaScript object, which will then be very easy to manipulate. I do not know that you have an array, but you can do something like this:
$.ajax({ url: '/my/site', data: {action: 'test'}, type: 'post', success: function(data) { var obj = jQuery.parseJSON(data); alert(obj.name[0] === "John"); } });
Again, the data variable here will contain all your PHP outputs, but JSON is the usual and convenient way to pass data back to your JavaScript.
source share