Javascript Simple Ajax Class
funcion.js
var AJAX_Handler = function()
{
this.xmlHttp = false;
try{
this.xmlHttp = new XMLHttpRequest();
}catch(e){
try{
this.xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
this.xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
alert('Your browser does not support AJAX');
return;
}
}
}
this.onreadystatechange = function(updateFunc){
this.updateFunc = updateFunc;
}
this.send = function(url,param){
param = param ? param : "";
this.xmlHttp.onreadystatechange = this.updateFunc;
this.xmlHttp.open("POST", url, true);
this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.xmlHttp.setRequestHeader("Content-length", param.length);
this.xmlHttp.setRequestHeader("Connection", "close");
this.xmlHttp.send(encodeURI(param));
this.handler = this.xmlHttp;
}
}
b.php
<?
if($_GET['tab'] == 2){
echo 'tab 21';
}
elseif($_GET['tab'] == 3){
echo 'tab 3';
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script src="function.js"></script>
<script>
function Send(value)
{
var ajax = new AJAX_Handler();
ajax.onreadystatechange(act_done);
ajax.send("b.php?tab="+value);
function act_done()
{
if(ajax.handler.readyState == 4 && ajax.handler.status == 200){
document.getElementById('show').innerHTML = ajax.handler.responseText;
}
}
}
</script>
</head>
<body>
<a href="#" onclick="Send(2)">Tab 2</a>
<br />
<a href="#" onclick="Send(3)">Tab 3</a>
<div id="show"></div>
</body>
</html>
<? }?>
http://www.mediafire.com/?0lxjiw86x9pplk9
funcion.js
var AJAX_Handler = function()
{
this.xmlHttp = false;
try{
this.xmlHttp = new XMLHttpRequest();
}catch(e){
try{
this.xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
this.xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
alert('Your browser does not support AJAX');
return;
}
}
}
this.onreadystatechange = function(updateFunc){
this.updateFunc = updateFunc;
}
this.send = function(url,param){
param = param ? param : "";
this.xmlHttp.onreadystatechange = this.updateFunc;
this.xmlHttp.open("POST", url, true);
this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.xmlHttp.setRequestHeader("Content-length", param.length);
this.xmlHttp.setRequestHeader("Connection", "close");
this.xmlHttp.send(encodeURI(param));
this.handler = this.xmlHttp;
}
}
b.php
<?
if($_GET['tab'] == 2){
echo 'tab 21';
}
elseif($_GET['tab'] == 3){
echo 'tab 3';
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script src="function.js"></script>
<script>
function Send(value)
{
var ajax = new AJAX_Handler();
ajax.onreadystatechange(act_done);
ajax.send("b.php?tab="+value);
function act_done()
{
if(ajax.handler.readyState == 4 && ajax.handler.status == 200){
document.getElementById('show').innerHTML = ajax.handler.responseText;
}
}
}
</script>
</head>
<body>
<a href="#" onclick="Send(2)">Tab 2</a>
<br />
<a href="#" onclick="Send(3)">Tab 3</a>
<div id="show"></div>
</body>
</html>
<? }?>
http://www.mediafire.com/?0lxjiw86x9pplk9