Code: Select all
function functionBlock($blockArray)
{
$output = "";
$title = $blockArray['title'];
$entryArray = $blockArray['entries'];
$rand = rand();
$throbberName = "throbber" . $rand;
$throbberBG = $throbberName . "bg";
$_SESSION['throbbers'][] = $throbberName;
session_write_close();
echo print_r($_SESSION['throbbers']);
$output .=<<<EOO
<div class="headercontainer">
<div class="throbberleft"></div>
<div class="headertext">$title</div>
<div class="throbberright" id="$throbberBG"><img src="images/indicator.gif" class="throbber" id="$throbberName"></div>
</div>
<div class="optioncontainer">
EOO;
$body ="";
foreach($entryArray as $entry)
{
$function = $entry['function'];
$callback = $entry['callback'];
$label = $entry['label'];
$output .="<div class=\"options\" onClick=\"send_command('$throbberName','$function','$callback','red')\" style=\"cursor:pointer\">$label</div>";
}
$output .= "</div>";
return $output;
}Code: Select all
function send_command(throbber, PHPfunc, callback, resetcolor)
{
document.getElementById(throbber).style.visibility='visible';
var bg = throbber + 'bg';
document.getElementById(bg).style.background='white';
agent.call("",PHPfunc,callback);
}The problem is when the link that's generated by this script is clicked (the onClick attribute), it can't see that $_SESSION['throbbers'] has been set at all. It returns a "undefined index" error.
Do I have to do something to ensure the $_SESSION update happens in the right scope here? As far as I can tell there's three separate requests:
1) the initial pageload from the browser;
2) the onLoad request; and
3) the request from clicking on the link generated from the previous request.
Changes to the $_SESSION array don't seem to be carried forward from 2 to 3. The way I have my site designed, this sort of modification to the $_SESSION is very important, and if I need to change something, now's the time (as in perhaps not using AjaxAgent? it doesn't seem very popular..)
Thanks for any insight.