March 29, 2017

SAJAX :Sample Ajax Toolkit

What is Sajax?

Sajax is another Ajax framework which makes it easy to call ASP, Cold Fusion, Io, Lua, Perl, PHP, Python or Ruby functions from your webpages via JavaScript without performing a browser refresh.

How does SAJAX work?

SAJAX creates a JavaScript stub function that calls functions you export from your script. It handles all the connection details and calls a callback function of your design when the data is available. Here’s an example of how easy it is to use:

  1. Include the library:
  2. Initialize it and tell it what functions you wish to export:
  3. Setup your HTML (including the JavaScript the library generates)

function set_math_result(result) {
document.getElementById("z").value = result;
function do_the_math() {
var x, y;
x = document.getElementById("x").value;
y = document.getElementById("y").value;
// our php function multiply() has been
// linked to a javascript function named
// x_multiply(). call it.
x_multiply(x, y, set_math_result);
<input type="text" name="x" id="x" value="2" size="3">
<input type="text" name="y" id="y" value="3" size="3">
<input type="text" name="z" id="z" value="" size="3">
<input type="button" name="check" value="Calculate"
onclick="do_the_math(); return false;">