February 26, 2017


JPSpan is an Ajax framework built with the intention of integrating client-side JavaScript with serverside code written in PHP. Download

JPSpan works by analyzing a PHP class using reflection. It then emits a number of JavaScript methods that accept the same arguments as the methods of the class on the server. When one of these methods is called, it uses a cross-browser library to instantiate the appropriate XmlHttpRequest for the platform it is running on and posts the data to the server. The response is then read and passed to a function on the client for further use within the page.

An Example Using JPSpan

// Including this sets up the JPSPAN constants
require_once '/path/to/JPSpan.php';
// Load the PostOffice server
require_once JPSPAN . 'Server/PostOffice.php';
// Some class you've written...
class HelloWorld {
function sayHello($name) {
return 'Hello '.$name;
// Create the PostOffice server
$S = & new JPSpan_Server_PostOffice();
// Register your class with it...
$S->addHandler(new HelloWorld());
// This allows the JavaScript to be seen by
// just adding ?client to the end of the
// server's URL
if (isset($_SERVER['QUERY_STRING']) &&
strcasecmp($_SERVER['QUERY_STRING'], 'client')==0) {
// Compress the output Javascript (e.g. strip whitespace)
// Display the Javascript client
} else {
// This is where the real serving happens...
// Include error handler
// PHP errors, warnings and notices serialized to JS
require_once JPSPAN . 'ErrorHandler.php';
** // Start serving requests...**