I have a php-function to fetch events as objects and I want to add them to my existing ul-list via JQuery. I want to transfer the php-variable to JQuery and want to iterate this variable to build up the HTML. I tried it with this one:
$pastEvents = event::getPastEvents($team);
var test = { pastEvents : '<?php echo $pastEvents; ?>' };
for (obj in test.pastEvents) {
console.log(obj);
}
The result i get is only 0, 1, 2, 3, 4, 5,... in the console. The var_dump from PHP looks like this:
array(8) { [0]=> object(game)#10 (17) { ["creatorid":protected]=> int(1) ["tid":protected]=> int(1) ["eid":protected]=> int(12) ["art":protected]=> int(1) ["spielart":protected]=> int(1) ["zeitpunkt":protected]=> string(19) "2012-02-28 11:20:00" ["zeit":protected]=> string(19) "2012-02-18 11:21:50"
How can i access the objects from PHP? How can i iterate the variable correctly, that i can access the data like obj.creatorid ... ?
Thanks!
P.S: I could solve this by using jquery's ajax-function - but before the user clicks i already have the data available - so the ajax-request is needless.