rendered paste body<?phpif ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { echo 'ajaxxed'; $bar = new Example($_REQUEST['thing']);}class Example{ private $id, $name, $section; public function __construct($id, $stuff) { $this->id = $id; foreach ($stuff as $key => $value) { $this->$key = $value; } if ($_REQUEST['thing']) { $this->doStuff(); } else { $this->dontDoStuff(); } } public function doStuff() { $this->id = $_REQUEST['thing']; echo $this->id.' corresponds to '.$this->name.', which lives in the '.$this->section; } public function dontDoStuff() { $uri = 'class.example.php'; echo "<p> No soup for you! <a href=\"?thing=$this->id\" onclick=\"ajax('$uri', 'thing', $this->id); return false;\"> Make soup? </a> </p>"; }}?><?php//-------display.example.php-------require_once 'class.example.php';?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <script type="text/javascript"> //<![CDATA[ function ajax(uri, param, value) { var xhr = false; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open('get', uri + '?' + param + '=' + value, false); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.onreadystatechange = function() { if ((xhr.readyState == 4) && (xhr.status == 200)) { alert(xhr.responseText); } }; xhr.send(null); } //]]> </script> <title>Rate</title></head><body><?php$foo = new Example(101, array( 'name' => 'Some article', 'section' => 'bin',));?></body></html>