About Us
LAJAX Class
by Lance Hallberg, FM Synergy
with contributions from Andy Gaunt of FMPug

Version 1.1
Definition: LAJAX is a free open-source JavaScript class. It wraps complex Ajax code so you can call the LAJAX functions and rely on the class to do the work for you. LAJAX has been tested on most current browsers and requires JavaScript 1.2.
Abstract: LAJAX allows you to call an external page ( .html, .php etc ) without refreshing the current page and returns the results of the page back to your own Javascript function ( which can assign the text to any DIV or other DOM object on the page). It is ideal to have the called script contain PHP, make some database transactions, then output via echo or print which returns the resulting HTML to your Javascript function.
Instantiation: LAJAX instantiates itself and has no instance methods or properties; it makes no sense to create multiple LAJAX instances.
Functions: LAJAX has 4 class functions
LAJAX.state()
Returns the ready state of the HTTPRequest object. If less than 4 your data is not back from the server yet.
LAJAX.result()
Returns your data that was sent back from the called page if LAJAX.state() == 4
LAJAX.get( string url, function function [, string params ] )
Tells LAJAX to invoke the external script at 'url' using the GET method. LAJAX will call 'function' (your user defined function) when the state changes (1-4); use LAJAX.state() to check. The user function may be passed inline. When LAJAX.state()==4 your data is waiting in LAJAX.result().
NOTE: Params should be name=value[&name2=value2...] format.
LAJAX.post( string url, function function [, string params ] )
Tells LAJAX to invoke the external script at 'url' using the POST method. LAJAX will call 'function' (your user defined function) when the state changes (1-4); use LAJAX.state() to check. The user function may be passed inline. When LAJAX.state()==4 your data is waiting in LAJAX.result().
NOTE: Params should be name=value[&name2=value2...] format.
Note: JavaScript uses a "Same as Origin" security rule which means this LAJAX object can't request, include or call any page outside of it's bound domain. If the page (url) you want to call is outside the domain of your LAJAX page, it won't work.

However, a work around is to have LAJAX call a script in the bound domain, and have that script make a request to the outside page ( using PHP include for example ) and return the result. I haven't tested this but I'm sure it will work.

For suggestion or feed back please email lance@fm-synergy.com

Any code contributions or suggestion please notify Lance Hallberg. For an example of how to use the LAJAX object, view the source for this page and/or download the LAJAX source code here.

LAJAX Example

Load Post Data
Enter data and click 'Load Post Data'. LAJAX passes your data to the called page. The page executes PHP code that displays the $_POST array, which comes back to the javascript function updatePost(). Notice this page, index.html, does not refresh.
Load Get Data
Enter data and click 'Load Get Data'. LAJAX passes your data to the called page. The page executes PHP code that displays the $_GET array, which comes back to the javascript function updateGet(). Notice this page, index.html, does not refresh.