Send As SMS

Anything Anywhere

Anything Anywhere...


Text Link Ads
Google
 
Web deproxy.bizhat.com

Friday, September 08, 2006

Ajax Lib - Now do Ajax in just a few lines of code!! - This Post

I just designed an Ajax library in javascript (just 1.16kb). The script is done in pure javascript so you can use it with any server side languages!

*Currently only the Get method is supported

Download: Click Here

Example: Add


Consider the following as the server-side script (add.php):

if($HTTP_GET_VARS['Action']=="Add")
{
echo
$HTTP_GET_VARS['a']+$HTTP_GET_VARS['b'];
exit;
}
?>
The file called at the browser (calc.htm):

< html >
<head>
<title>Ajax Lib - Add</title>
<script language="javascript" src="Ajax.lib.js"></script>
<script language="javascript">
<!--

var xAdd = new Ajax('add.php','get');

xAdd.onError = function(code)
{
alert("Error "+code);
}

xAdd.onResponse = function(Res)
{
if(Res.State == 4) //if Initialized
{
document.getElementById("result").innerHTML=Res.Text;
}
}

function Add()
{
var a = document.getElementById("a").value;
var b = document.getElementById("b").value;
xAdd.Go('Action=Add&a='+a+'b='+b);
}

-->
</script>
</head>
<body>
<input type="Text" id="a"> +
<input type="text" id="b"> =
<span id="Result"> </span>
<input type="button" onclick="javascript: Add(); value="Add">
</body>
</html>

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home