Tuesday, February 21st, 2006

TinyAjax: Another PHP 5 Ajax Library

Category: Ajax, PHP, Toolkit

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.


  • 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.

  1. < ?php
  3.     define('TINYAJAX_PATH', '../include');
  4.     require_once("../include/TinyAjax.php");
  6.     function multiply($x, $y) {
  7.         $res = $x * $y;
  9.         $tab = new TinyAjaxBehaviour();
  10.         $tab->add( TabSetValue::getBehaviour("third_id", $res));
  11.         return $tab->getString();
  12.     }
  15.     $ajax = new TinyAjax();
  16.     $ajax->exportFunction("multiply", array("first_id", "second_id"));
  18.     $ajax->process();  
  19. ?>
  20. <html>
  21. <head>
  22. < ?     $ajax->drawJavaScript(false, true); ?>
  23. </head>
  24. <body>
  26. Multiply example:<br />
  28. <input type="text" id="first_id" value="2"/> *
  29. <input type="text" id="second_id" value="3"/> =
  30. <input type="text" id="third_id" value=""/>
  31. <input type="button" value=" * " onclick="multiply()"/>
  33. </body></html>

Posted by Dion Almaer at 8:06 am

3.9 rating from 118 votes


Comments feed TrackBack URI

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.

Comment by Dmytro Shteflyuk — February 21, 2006

They forgot to use their define()’d variable. :P

Comment by Garret — February 21, 2006

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.

Comment by Brian — February 21, 2006

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

Comment by Ted Smith — February 21, 2006

Can you help me? I have problems in my code, and the error is missing bevaior? This is my code….


} // end function view

$ajax = new TinyAjax();

My First Ajax Application

Add a car:

Comment by Rey — August 29, 2006

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.

Comment by Brian — May 23, 2007

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.

Comment by Nahuel Alejandro Ramos — June 14, 2007

Leave a comment

You must be logged in to post a comment.