13.1. JPSpan

JPSpan is an open source Ajax framework for PHP (available for download at www.sourceforge.net/projects/jpspan) that creates JavaScript wrappers for PHP objects and methods. It accomplishes this task by using reflection to inspect the composition of an object. Reflection is a common feature of object-oriented languages, allowing developers to determine information about the makeup of an object at runtime. By using reflection, JPSpan is able to create appropriate JavaScript wrappers for each method of the object. These JavaScript functions handle the cross-browser creation of XHR objects as well as the instantiation of objects on the server and data type conversion of arguments and results.

What's more, since JPSpan is simply a series of PHP pages and JavaScript files, there is no real installation to speak of. Simply download the files from the previously mentioned web site and copy the JPSpan folder to the PHP web server.

13.1.1. Using JPSpan

Most of the coding for a JPSpan Ajax solution takes place on the server using a PostOffice object. The PostOffice object is responsible for two things: generating the JavaScript for the client and handling Ajax requests on the server. Generally speaking, the same PHP file handles both activities, depending on the query string of the request. The standard way of doing this using JPSpan is to have the query string equal to "client" when the JavaScript wrappers should be generated (for example, myserver.php?client) and to omit ...

Get Professional Ajax, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.