现在的位置: 首页 > 综合 > 正文

Ajax的应用

2012年05月02日 ⁄ 综合 ⁄ 共 1923字 ⁄ 字号 评论关闭
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Blank Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
        var url, x, empName, empNo, empCount, txt;
        var xmlHttp;
        function createXmlHttpRequest() {
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlHttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }

        //刷新
        function refeshData(url) {
            var url = url;
            createXmlHttpRequest();
            xmlHttp.onreadystatechange = DisplayData;
            xmlHttp.open("GET", url, true);
            xmlHttp.send();
            setTimeout("refeshData('" + url + "')", 80);
        }

        function DisplayData() {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    if (x == null) {
                        x = xmlHttp.responseXML.documentElement.getElementsByTagName("SingleTable");
                        empCount = x.length - 1;  //防止下面取值數組溢出
                    }
                    if (empCount > 0) {
                        empName = x[empCount].getElementsByTagName("NAME");
                        empNo = x[empCount].getElementsByTagName("EMPLOYEE_NO");
                        txt = empName[0].firstChild.nodeValue + "  " + empNo[0].firstChild.nodeValue;
                        document.getElementById("count").innerHTML = txt;
                        empCount--;
                    }
                }
            }
        }

        function init(url) {
            window.setTimeout("refeshData('" + url + "')", 800);
        }
    </script>
</head>
<body scroll="no" bgcolor="#eeeeee" onload="init('Ajax/db.xml');">
    <!-- onload="init('Ajax/db.xml');"-->
    <table width="100%" height="700" background="images/lott.jpg">
        <tr>
            <td>
                <div id="count" style="text-align: center; text-decoration: underline; font-family: Arial, Helvetica, sans-serif;
                    font-size: 100px; font-weight: bolder">
                    MITAC 00000</div>
                <div style="text-align: center; font-family: Tahoma; font-size: 20pt; font-weight: bolder">
                    Loading......
                    <br />
                    <br />
                    <br/>
                    <input id="Button1" type="button" style="background-position: 0% 0%; height: 64px;
                        width: 208px; background-color: #FF0000; background-attachment: inherit; border-color: Red;
                        background-image: url('Images/end.gif'); background-repeat: repeat;"  onclick="window.close();"  />
            </td>
            </div>
            <!--<button onclick="refeshData('Ajax/db.xml')">
                    start</button>-->
        </tr>
    </table>
</body>
</html>

 

抱歉!评论已关闭.