Try using JSON. PHP function json_encode ()
EDIT: Sample code (server side - PHP):
// data handling $arrayToSend = array(array('name'=>'Most Recent', 'view'=>'recentView'), array('name'=>'Most Popular', 'view'=>'popularView'), array('name'=>'Staff Picks', 'view'=>'staffView')); echo json_encode($arrayToSend);
Client side (javascript). Note. YUI is used to display client-side processing:
var callback = {success: function(req) { selectItems(req.responseText); } }; YAHOO.util.Connect.asyncRequest('GET',url + '?param=1',callback); function selectItems(resp) { var result = eval('(' + resp + ')'); for (var i=0; i < result.length; i++) {
Comments : 1) In a PHP script, you need to make an answer that outputs your array, pre-encoded in JSON format. 2) In addition to YUI, you can also use any appropriate JavaScript library to generate an AJAX request (i.e. JQuery , Prototype ). In my case, I used the eval () function to make an array from a JSON response.
Hope this helps you.
source share