Location: PHPKode > projects > PRAjax - PHP Reflected Ajax > examples/example_helloworld_prototype.php.txt
<?php
// Set the header
header("Content-Type: text/html; charset=utf-8");

// Use bin or src?
$strSources = '../bin';

// Import PRAjax
require_once($strSources . '/PRAjax.php');

// Instantiate PRAjax
$objPRAjax = new PRAjax($strSources . '/');

// Register functions
$objPRAjax->RegisterFunction('HelloWorld');
$objPRAjax->ShowWaitCursor();
$objPRAjax->setUsePRAjaxTransport(false); // Do not use PRAjaxTransfer

// Handle PRAjax client request
$objPRAjax->HandleClientRequest();

// Functions
function HelloWorld() {
	return "Hello World! " . date("Y/m/d H:i:s");
}
?>
<html>
	<head>
		<title>Hello World</title>
		
		<?php $objPRAjax->GetJavaScript(); ?>
		<script language="JavaScript" src="prototype.js"></script>
		<script language="JavaScript">
		<!--
		// Transport factory
		PRAjax.CreateTransfer = function () {
			return new CustomTransport();
		}
		
		// Custom transport class, must implement PerformRequest(uri, post_data, callbackFunction, errorFunction, openCallCount)
		function CustomTransport () {}
		CustomTransport.prototype.PerformRequest = function (uri, post_data, callbackFunction, errorFunction, openCallCount) {
			var ajax = new Ajax.Request(uri, {method: 'post', parameters: post_data, onSuccess: function (xmlObj) { callbackFunction(xmlObj.responseText); }, onFailure: errorFunction} );
		}
		
		// Callback functions
		function HelloWorld_cb(data) {
			alert(data);
		}
		// -->
		</script>
		
		<style type="text/css">
		<!--
		body, p, td {
			font-family: Arial, Helvetica, sans-serif;
			font-size: 11px;
		}
		h1 {
			font-size: 22px;
			font-weight: bold;
		}
		h2 {
			font-size: 18px;
			font-weight: bold;
		}
		-->
		</style>
	</head>
	
	<body>
		<div style="width: 100%; height: 65px; background-color: #EEEEEE; font-family: Arial, Helvetica, Sans-Serif; font-size: 9pt;">
			This example demonstrates a simple Hello World example, using an external transport (prototype.js). Be sure to check out the transport factory in the source code.
			<br>
			<a href="example_helloworld_prototype.php.txt" target="_blank">View code...</a>
		</div>
		
		<form name="frmForm">
			<h1>Hello World</h1>
			<input type="button" value="Simple Hello World" onClick="HelloWorld(HelloWorld_cb);">
		</form>
	</body>
</html>
Return current item: PRAjax - PHP Reflected Ajax