I'm having difficulty trying to return a multi-demensional array using Javascript Prototype's Hash Object. I have been able to return the values of the following associative php array using JSON and Javascript Prototype's Hash Object:

php array

$player = array(
					'PlayerName' => 'Ron Artest',
					'Position' => 'Forward',
					'Height' => '6-7',
					'Weight' => '260',
					'College'=> 'St. Johns');

Javascript Code used to return values of array:

var request = new Ajax.Request('jsonEncode.php',
    {
        onSuccess: function(request)
            {
                var emptyAssociativeArray = request.responseJSON;
                
                

                 emptyAssociativeArray= (Object.isArray(emptyAssociativeArray) && !emptyAssociativeArray.length) ? {} : emptyAssociativeArray; 
$H(emptyAssociativeArray).each(function(pair) {
   $('workaroundOutput').insert('<div>' + pair.value + '</div>');
});
            },
        method: 'get',
        parameters:
            {
                team: 'LA Lakers'
            }
    });

BUT, when I try to return the following I run into a snag.

$player = array(
						array(
					'PlayerName' => 'Ron Artest',
					'Position' => 'Forward',
					'Height' => '6-7',
					'Weight' => '260',
					'College'=> 'St. Johns'),
					
						array(
					'PlayerName' => 'Kobe Bryant',
					'Position' => 'Guard',
					'Height' => '6-6',
					'Weight' => '205',
					'College'=> 'Lower Marion High Sc')
					);

PLEASE HELP!!

Your data is now two levels deep so you ned nested loop in your onsuccess handler to access it.

It will be something like:

$H(emptyAssociativeArray).each(function(player) {
    $H(player).each(function(pair) {
       $('workaroundOutput').insert('<div>' + pair.value + '</div>');
    })
});

You may need to check the Protoype API to see if $H(...).each works with an indexed array.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.