function AJAX_Handler() { 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 (_func) { this.xmlHttp.onreadystatechange = _func; } this.send = function (url, param) { param = param ? param : ""; 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
<!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 Ajax_Request(url, param) { var ajaxObj = new AJAX_Handler(); ajaxObj.onreadystatechange(act_done); ajaxObj.send(url, param); function act_done() { if(ajaxObj.handler.readyState == 4 && ajaxObj.handler.status == 200){ document.getElementById('show').innerHTML = ajaxObj.handler.responseText; } } } </script> </head> <body> <a href="#" onclick="Ajax_Request('abc.php','a=b&c=d')">Tab 2</a> <div id="show"></div> </body> </html>
Download: http://www.mediafire.com/?0lxjiw86x9pplk9
(Sưu tầm)