You are here: Re: Functions for variables « PHP Programming Language « IT news, forums, messages
Re: Functions for variables

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация