Sajax is a ‘managed’ AJAX framework that was created by the fine folks at Modern Method a few years ago.
What’s so great about it is the seamless communication between your back-end and the web page itself: you write your PHP code, tell Sajax which functions to export and they are now accessible from Javascript.
For instance — from the ‘example_types.php’ file:
function return_string() { return "Name: Tom / Age: 26"; } |
The corresponding Javascript call would be:
<button onclick="x_return_string(display_result);">Return as string</button> |
OK so this is a pretty great package, no doubt.
Unfortunately there are exactly three things that bother me here:
- The choice to prefix all remote calls with ‘x_’ which feels less natural, even though it is a convenient way to avoid namespace collisions.
- More importantly, Sajax does not support PHP classes and I am not comfortable working with strictly procedural code. After all, object-oriented PHP has been around for quite some time now.
- Of course, it would seem that the last Sajax release happened sometime in 2006, which would explain #2
Thus, S2ajax was born.
If supports classes and methods, does not require prefixing and the export() calls are now more powerful.
The syntax is still very straightforward and relies on clean Javascript code.
And the license, obviously, is still the very open BSD.
Additionally, this S2ajax can be easily integrated with PHP 5’s magic class and methods loading. For instance, it works with my own PHP framework.
As usual, all this goodness is available at github.com!







I just downloaded the S2ajax, that i thing is a great ideea, beacause I searched for Sajax suport for OO for a long time, and i didn’t have time and experience to write it myself. After a few test it seems to work just fine with OO PHP.
I thing that the folks from Modern Method should get this code, check it and optimize it (if needed), and put it as the new Sajax version on their own site with credit to the creator of this great upgrade, beacause that is the place where many people start looking for an upgrade for the great Sajax package.
@Radu –
Very good point!
I will talk to the Modern Method people, see if they have any interest.
How can I do something like this with Sajax:
beacause the test() class is not intialize I cannot use this->sql beacause it doesn’t exist without the class instantiation.
class sql(){
…functions to work with MySql database
function select(){
… select something from database mysql_wquery()
}
}
class test(){
function __construct(){
$this.sql = new sql;
}
function myquery(){
$this->sql->select(“select now()”);
}
}
HTML…
function ret(time){
alert(‘time is’ + time);
}
END HTML
Thank you.
It seems that the a part of HTML code was missing from the previous comment
HTML…
function ret(time){
alert(‘time is’ + time);
}
END HTML
@Radu – @Radu –
Radu, please download the latest version: it allows you to instantiate classes on demand.
I would like to know if this solves your issue as, in theory, it should, but there is a caveat and it’s that resources cannot be persisted. Therefore, depending on your sql wrapper implementation, it may allow you to do what you want — or not. But pure class instantiation certainly is something that had been sorely missing.
I will give it a try and reply, bug right now I am working on some deadline projects so my agenda is full …