Javascript Simple Ajax Class

Hiện tại, vì công việc quá bận rộn nên mình không còn thời gian để post bài và duy trì nội dung cho blog nữa. Do đó tại thời điểm này, mình quyết định ngừng phát triển blog. Mọi bài viết sẽ vẫn được lưu trữ và mình sẽ cố gắng hỗ trợ tất cả các bạn khi có comment hỏi. Cảm ơn các bạn đã ủng hộ blog suốt thời gian qua !
funcion.js

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)
 

Web Design Technology blogs [ itdl ] Auto Backlink

HomeBlog ArchiveServicesLink2MeContactSubmit your PostPost RSS

Copyright © 2012 [ itdl ] Just for Share. Designed by Ngoc Luong - Freelancer

Best view in Chrome 11+, Firefox 5+ with resolution 1024 x 768 pixel. Powered by Blogger.