0

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!!

2
Contributors
1
Reply
3
Views
8 Years
Discussion Span
Last Post by Airshow
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.