Tuesday, February 21st, 2006
TinyAjax: Another PHP 5 Ajax Library
Mats Karlsson loved how simple it was to implement Ajax features with Sajax, but thought there was room to make it even simpler, so he created TinyAjax.
Features
- AJAX enable your pages without having to write a single line of javascript
- Call PHP functions in classes or as separate functions, you can even extend TinyAjax by subclassing it
- Let your PHP-code set which elements to alter and with what using behaviours
- Integrate it with a template system (smarty-example included)
- Easily have gmail style "Loading" notification when AJAX-code is executing
- Use PHP-functions for both AJAX callback and regular code
Simple Example
This pretty much shows you how it all works.
-
-
<?php
-
-
require_once("../include/TinyAjax.php");
-
-
function multiply($x, $y) {
-
$res = $x * $y;
-
-
$tab = new TinyAjaxBehaviour();
-
$tab->add( TabSetValue::getBehaviour("third_id", $res));
-
return $tab->getString();
-
}
-
-
-
$ajax = new TinyAjax();
-
-
$ajax->process();
-
?>
-
<html>
-
<head>
-
<? $ajax->drawJavaScript(false, true); ?>
-
</head>
-
<body>
-
-
Multiply example:<br />
-
-
<input type="text" id="first_id" value="2"/> *
-
<input type="text" id="second_id" value="3"/> =
-
<input type="text" id="third_id" value=""/>
-
<input type="button" value=" * " onclick="multiply()"/>
-
-
</body></html>
-












Just another Sajax clone :-) I think it’s too heavy in compare with Sajax (but both are simple of course). I don’t see any reasons to produce so much equal libraries.
They forgot to use their define()’d variable. :P
I don’t understand what the serious draw to trying to do as little javascript coding as possible. It benefits programmers a lot more to dig in a little and learn what’s going on. Otherwise you are stuck with this script kiddie mentality. Javascript has always been primarily a cut and paste language for so many people and now with the presence AJAX is commanding it’s finally an opportunity to open some eyes and learn a great language.
Networking: The end of ’shoulder surfing?
Some hackers like to “shoulder surf,” or steal unsuspecting PC users’ passwords by looking over their shoulders at the Internet café. Others prefer to crack an account’s password — using sophisticated software programs. But new developments in network security are going to wipe out the shoulder surfers, and their cracker pals, experts tell United Press International’s Networking.
Graphical passwords are emerging — images, not words or phrases, which authenticate access to a computer or a network. By Gene Koprowski
Can you help me? I have problems in my code, and the error is missing bevaior? This is my code….
Name
Manufucturer
“;
} // end function view
$ajax = new TinyAjax();
$ajax->showLoading();
$ajax->exportFunction(”view”,”);
$ajax->exportFunction(”insert”,array(”car”,”manufucturer”));
$ajax->process();
$ajax->drawJavascript();
?>
My First Ajax Application
Add a car:
Car
Manufucturer
One immediate advantage tinyajax over sajax is that it is neat. In that it does not dump its javascript when you call the necessary setup functions where tinyajax writes out its code when you call the drawJavaScript method, which is essential, if you are using Smarty.
I was horrified when I opened the sajax library.
It is and incredible work. I change some code in getPostData() function that let me send multiple values on a single variable as and Array. I modified it because I need get values from checkboxes with the same name. Example:
The new getPostData() for me is:
public static function getPostData($data) {
$row = split(”!ROW!”, $data);
$arr[] = “”;
foreach($row as $val) {
$tmp = split(”!COL!”, $val);
if(sizeof($tmp) > 1) {
if (array_key_exists($tmp[0], $arr)) {
if (is_array($arr[$tmp[0]])) {
$subTmp = $arr[$tmp[0]];
$subTmp[] = $tmp[1];
$arr[$tmp[0]] = $subTmp;
} else {
$subTmp = array();
$subTmp[] = $arr[$tmp[0]];
$subTmp[] = $tmp[1];
$arr[$tmp[0]] = $subTmp;
};
} else {
$arr[$tmp[0]] = $tmp[1];
};
} else {
$arr[$tmp[0]] = “”;
};
}
$_POST = $arr;
return $arr;
}
Thanks for that perfect scripts.