This is an AJAX/Prototype problem, which is independent of the server-side scripting language I'm currently using. I have the following multi-demensional nested array, which I have successfuly turned into a JOSN Object as such:
[{"PlayerName":"Ron Artest","Positn":"Forward","Height":"6-7 l","Weight":"260","College":"St. Johns"},
{"PlayerName":"Kobe Bryant","Positn":"Guard","Height":"6-6 l","Weight":"205","College":"Lower Marion High Sc"},
{"PlayerName":"Andrew Bynum","Positn":"Center","Height":"7-0 l","Weight":"285","College":"St. Josephs"},
{"PlayerName":"Pau Gasol","Positn":"Forward","Height":"7-0 l","Weight":"250","College":"Spain"},
{"PlayerName":"Derick Fisher","Positn":"Guard","Height":"6-1 l","Weight":"210","College":"Arkansas-Little Rock"}]
I'm currently using the firbug console and the following code is telling me that I have a successful Object available to me:
var request = new Ajax.Request('dropDownMenu_ajax.php',
{
onSuccess: function(request)
{
var players = request.responseJSON;
console.log(players);
},
method: 'get',
parameters:
{
team: 'LA Lakers'
}
});
The issue occurs when it is time for me to parse this data and render it in a browser where I can make some use of it. The below for loop give me results, but clumps everything together:
var request = new Ajax.Request('dropDownMenu_ajax.php',
{
onSuccess: function(request)
{
var players = request.responseJSON;
console.log(players);
for (var team in players){
for (var member in players[team]){
$('workaroundOutput').insert(players[team][member]);}}
},
method: 'get',
parameters:
{
team: 'LA Lakers'
}
});
The above code gives me the following, all jumbled together:
Ron ArtestForward6-7 l260St. JohnsKobe BryantGuard6-6 l205Lower Marion High ScAndrew BynumCenter7-0 l285St. JosephsPau GasolForward7-0 l250SpainDerick FisherGuard6-1 l210Arkansas-Little Rock
When I try and separate the result with a <br/> my using
$('workaroundOutput').insert(players[team][member] + '<br/>');}}
instead of
$('workaroundOutput').insert(players[team][member]);}}
I get something crazy. I get the results, but after that it seems like I'm getting get all the prototype extensions to the Array object along with an empty object
Ron Artest
Forward
6-7 l
260
St. Johns
Kobe Bryant
Guard
6-6 l
205
Lower Marion High Sc
Andrew Bynum
Center
7-0 l
285
St. Josephs
Pau Gasol
Forward
7-0 l
250
Spain
Derick Fisher
Guard
6-1 l
210
Arkansas-Little Rock
[object Object]
function () { var names = this.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1].replace(/\s+/g, "").split(","); return names.length == 1 && !names[0] ? [] : names; }
function () { if (arguments.length < 2 && Object.isUndefined(arguments[0])) { return this; } var __method = this, args = $A(arguments), object = args.shift(); return function () {return __method.apply(object, args.concat($A(arguments)));}; }
function () { var __method = this, args = $A(arguments), object = args.shift(); return function (event) {return __method.apply(object, [event || window.event].concat(args));}; }
How would I properly parse and traverse this JSON Object.