AJAX简单实现(JS)

<script type="text/javascript">

        var xmlhttp = new ActiveXObject("Microsoft.XMLhttp");
        function send() {
      
            xmlhttp.Open("POST", "Handler.ashx?r=" +Math.random(), "True");
            xmlhttp.send();
            xmlhttp.onreadystatechange = ServerProcess;

        }

//        readyState的取值如下:
//        0 (未初始化)
//        1 (正在装载)
//        2 (装载完毕)
//        3 (交互中)
//        4 (完成)

        function ServerProcess() {

            if (xmlhttp.readystate == 4 || xmlhttp.readystate == 'complete') {
                document.write(xmlhttp.responsetext);
           
            }

        }
        //setInterval('send()', 1000);
     
   
    </script>

你可能感兴趣的:(Ajax)