|
Posted by paladin.rithe@gmail.com on 04/03/06 19:58
Like I said, I'm using XMLHttpRequest (XHR) in JavaScript to get the
web pages, and update it dynamicly. I have multiple div id's that need
updated at each call, so I needed to find a way to do this. One way
was to make multiple XHR calls, possibly with multiple XHR objects.
Another way just uses one, send back JavaScript code, and use eval() in
JavaScript to run it. Here's a rough idea:
<?php
class Output
{
var $main;
var $menu;
function main($script)
{
$main .= $script;
}
function menu($script)
{
$menu .= $script;
}
function display()
{
print "var menu = {$menu};";
print "var main = {$main};";
print "menuUpdate(menu);";
print "mainUpdate(main);";
}
}
?>
So, in the php script, that uses the Output class, you would have
something like (where out is the Output variable:
out.menu('<a href="option1.php">Option1</a>');
out.menu('<a href="option2.php">Option2</a>');
out.menu('<a href="option3.php">Option3</a>');
out.main('<p>This is paragraph one</p>');
out.main('<p>This is another paragraph</p>');
out.main('<p>The last paragraph</p>');
out.display();
Now, what is printed ends up stored in the responseText that is
returned to the JavaScript. I have 2 JS functions, updateMenu(), and
updateMain() that update their respective areas when called with the
html as a parameter.
Since I have multiple (more than those 2) variables, it would be nice
to have something where I can define one function, and it updates the
correct variable. But, if I have to do all of them manually, it's not
a big deal. They're simple enough. I just thought I'd try to save
myself a little time.
Navigation:
[Reply to this message]
|