Javascript Serializer

Description

The purpose of this script is to transform PHP variables into Javascript variables so that an HTML page can call a PHP script without having to be reloaded on each call.

History

There are many manners of reaching a webservice from Javascript. But the only one I know which is compatible with almost all the navigators is the one used here which consists in calling a PHP script that returns Javascript variables that are directly evaluated by the HTML page.

This script had many success since the first time I put it on line in 2002 and many people were inspired by to create applications (PHP or others) able to send serialized data to Javascript. The most known being JPSpan published on SourceForge under open-source GPL licence that is in respect with the GPL licence used in my own script.

I want to thank all of you who sends me positive words about this script and also thank originals programmers of AMFPHP which I took as a starting point to write this one.

Downloading the serializer script and installing a gateway

Download the main script

Installation :
  1. Download the serializer script above
  2. The archive contains a PHP file named js_serializer.php. This file contains the PHP class used to serialize the data returned by the webservice.
  3. This file will never be called directly from HTTP. It can thus be installed in the include directory of your server or anywhere else. It just need to be called by the gateway script as an include file.
  4. If you just want to call a php script from Javascript you just have to include and call js_serializer.php file within your PHP script and dump the serialized result to the output.
  5. To access any nuSOAP or AMFPHP webservice from Javascript, you just have to install one file that will be accessible from HTTP on your server. This file will be used as a gateway between PHP and the Javascript serialized data. It is exactly the same installation you could make with gateway.php from AMFPHP or NuSOAP. The only thing is that you probably will have here to create one gateway script for each webservice class you use.

Hello World !

Download the «Hello World !» example

To use the downloaded files, you just will have to deploy them as they are on your server as the example contains the main script. The application will work by calling the hello_world_example.html page contained in the archive.

Calculator example

This calculator ask the server to calculate the total of the operation. Nothing is calculated by Javascript and the communication with the server is made without to have to refresh the HTML page when the Calculate button is pressed.

Download the calculator example

To use the downloaded files, you just will have to deploy them as they are on your server as the example contains the main script. The application will work by calling the calculator_example.html page contained in the archive.

Real life use

An application used to illustrate monetary conversion webservice access is on the page devoted to the Javascript version of EuroConverter. This application contains the gateway file, js_serializer.php and the Javascript client, but not the webservice in itself which could not be easily distributed.

  rss rss english xhtml 1.1 css 2.0 wdg