AJAX in 60 seconds with My-BIC and PHP
My-BIC os one of the simplest AJAX frameworks today.
After you download script all you need to do is to put mybic.js and mybic_server.php in some directory on your web server and you are ready to go.
Here is the simple example of getting time from the server with ajax.
First we create test.html file:
<html>
<head>
<title>AJAX TEST</title>
<script type="text/javascript" src="mybic.js"></script>
<script>
var ajaxObj = new XMLHTTP("mybic_server.php");
function get_time(){
ajaxObj.call('action=get_time', 'content');
}
</script>
</head>
<body>
<div onmouseover="get_time();"> Show me the time ! </div>
<div id="content"> </div>
</body>
</html>
Now when we have frontend, we need to create php file to do background job. Since our function and action are named get_time we must create php file with same name.
So we create get_time.php:
<?
class get_time
{
var $queryVars;
function get_time($queryVars)
{
$this->qv = $queryVars;
}
/**
* Method to return the status of the AJAX transaction
*
* @return string A string of raw HTML fetched from the Server
*/
function return_response()
{
$a=date("H:i:s D-M-Y", time());
return ($a);
}
function is_authorized()
{
return true;
}
}
?>
Now all you need to do is to go with your mouse cursor over "show me the time" text and My-BIC will return time vie innerHTML into content div.
More info on My-Bic homepage
http://www.litfuel.net/mybic/