Cesar D. Rodas'
gAjax
Class


The author disclaims the copyright of this source.

I hope this code be useful for PHP community, please if you have more ideas of how to expand this project, bug report of something please take the time for write me at saddor@cesarodas.com


The basic idea of gAjax is to provide an easy way to migrate existed pages into an Ajax version, avoiding write javascript code and providing an api to manipulate HTML objects from PHP.

API Example

$ajax = new gAjax('js/');
$ajax->export("sumar");
$ajax->export("multiplicar");

The first line create an object of the Ajax class, in this example is used the gAjax - Prototype

The second and third line made Ajax visible the follow functions "sumar" and "multiplicar".

function sumar($a,$b) {
    return
$a + $b;
}
function
multiplicar($a,$b) {
    
$r = $a * $b;
    
    
$html = new gHtml;
    
$html->alert("This example also shows how to use gHttp");
    
/* Keep show the result in result2 */
    
$html->setObject('result2');
    
$html->setProperty('innerHTML',$r);
    
$html->alert("result2 now was changed");
    
/* The result is also the new size of the HTML object with id ID*/
    
$html->setObject('id');
    
$html->setProperty('rows', $r);
    
$html->setProperty('value',"Long's text\ncesar");
    
$html->alert("now the value rows");
    
/* Return the result also to the default function */
    
$html->alert("now the value is returned, if there is a function that get the return, it will be changed");
    return
$r;
}

The "sumar" function returns a value, that value is binding with an HTML object by its id as you can see in the example.

"multiplicar" is a better example because this changes html objects properties from php and also returns a value, which can be binding with an html object.

 

<?php
    $ajax
->execute("result","sumar",5, 10);
?>

The method execute execute binging the first parameter (also could be blank "") and execute the php "suma" function send parameters 5 10.


<input type="button" onclick="<? $ajax->execute('result1',false,"multiplicar",byvalue('a','value'), byvalue('b','value') );?>" value="Multiplicar!" /><br />

The other example is more interesting, it execute the function "multiplicar" (3rd parameter) and put the 2nd parameter in false which means do not print javascript tags. The results is binging to "results1" also could be blank. Here is used the function byvalue(htmlObject, property) as the parameters to the function this man it is callgin php: multiplicar( htmlObject1.value, htmlObject2.value) both parameters to php are dynamically¬ read from the html

The second parameter here is false because we do not want javascript tags be print, if we do want, simple ommit this parameter


Cesar D. Rodas <saddor@cesarodas.com>