How To Use SAJAX (AJAX Framework) from HTML
Sajax is an useful ajax framework to simplify ajax based development for languages like PHP, Ruby etc. Not many realize Sajax can be used equally well from plain old html pages (as in .html or .htm). Their website doesn't mention it anywhere so I can guess it was not one of their use cases. However sajax is based upon ajax which is plain old Javascript. Let's find out how we can use trusty old sajax to liven up your static pages.
To use sajax from html you need to get the javascript code it generates and include it in your html pages.
Sajax doesn't tell you how you can create a javascript file to include (in your html pages), thereby allowing you to call php (for example) function calls from client side javascript. This can however be remedied with a simple call:
This generates the required javascript file (change filename to your liking). Include this file in your html pages and you are good to go. Now you can call your exported php function from javascript. Remember to append the function names with x_.
How can you use it?
Check my Annotated wordPress source code cross-reference site for an example. Check out the sajax based commenting system.
PS. As a side tip you should know sajax_init() function call is not required and can be eliminated with current versions of Sajax. It does nothing.
Filed under CMS Software, Headline News, How To, Open Source Software, PHP, Pro Blogging, Tech Note, Web, Web Services, WordPress |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |


Add to Technorati Favorites


































January 14th, 2007 at 3:55 am
[...] There is a third and even simpler way to execute programs and display the results using AJAX. You can use any popular AJAX framework like Sajax or Prototype to make calls to the server and then display the results dynamically. This had the added advantage of being able to repeatedly update page contents. [...]
September 9th, 2007 at 9:50 am
Your site says “Remember to append the function names with x_.” In fact, in my experience the “x_” needs to be prepended, not appended.