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

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

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

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

// Register functions
$objPRAjax->RegisterFunction('HelloWorld');
$objPRAjax->RegisterFunction('HelloWorldParams');
$objPRAjax->RegisterFunction('HelloWorldArray');
$objPRAjax->RegisterFunction('HelloWorldServerSide');
$objPRAjax->ShowWaitCursor();

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

// Functions
function HelloWorld() {
	return "Hello World! " . date("Y/m/d H:i:s");
}

function HelloWorldParams($firstname = '', $lastname = '') {
	return "Hello, " . $firstname . " " . $lastname;
}

function HelloWorldArray($name) {
	return array("Hello", $name[0], $name[1]);
}

function HelloWorldServerSide($firstname = '', $lastname = '') {
	global $objPRAjax;

	$objPRAjax->Alert("Hello, " . $firstname . " " . $lastname);
}
?>
<html>
	<head>
		<title>Hello World</title>
		
		<?php $objPRAjax->GetJavaScript(); ?>
		<script language="JavaScript">
		<!--
		// Callback functions
		function HelloWorld_cb(data) {
			alert(data);
		}
		
		function HelloWorldParams_cb(data) {
			alert(data);
		}

		function HelloWorldArray_cb(data) {
			alert(data[0]);
			alert(data[1]);
			alert(data[2]);
		}
		// -->
		</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
			<br>
			<a href="example_helloworld.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);">
			<input type="button" value="Parameters Hello World" onClick="HelloWorldParams(prompt('Firstname:'), prompt('Lastname:'),  HelloWorldParams_cb);">
			<input type="button" value="Array Hello World" onClick="HelloWorldArray( new Array( prompt('Firstname:'), prompt('Lastname:') ),  HelloWorldArray_cb);">
			<input type="button" value="ServerSide Hello World" onClick="HelloWorldServerSide(prompt('Firstname:'), prompt('Lastname:'));">
		</form>
	</body>
</html>
Return current item: PRAjax - PHP Reflected Ajax