All pastes #898461 Raw Edit

jm

public php v1 · immutable
·published 2008-02-10 10:45 UTC
rendered paste body
<?php//-------class.example.php-------class Example{	private $id;		public function __construct($id)	{		$this->id = $id;		if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {			echo 'ajaxxed';			$this->doStuff();		} elseif ($_GET['thing']) {			$this->doStuff();		} else {			$this->dontDoStuff();		}	}		public function doStuff()	{		echo 'The id is '.($this->id + $_GET['thing']).'.';	}		public function dontDoStuff()	{		$uri = 'class.example.php';		echo "<p>			No soup for you!			<a href=\"$uri?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);?></body></html>