日期:2014-05-17  浏览次数:20815 次

通过XMLHTTP加载HTML文件
<html>
    <head>
        <script type="text/javascript">
            var xmlhttp;
            function loadXMLDoc(url){
                xmlhttp = null;
				// code for Firefox, Opera, IE7, etc.
                if (window.XMLHttpRequest) {
					xmlhttp = new XMLHttpRequest();
				}
				else {
					// code for IE6, IE5
					if (window.ActiveXObject) {
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					}
				}
                if (xmlhttp != null) {
                    xmlhttp.onreadystatechange = state_Change;
                    xmlhttp.open("GET", url, true);
                    xmlhttp.send(null);
                }
                else {
                    alert("Your browser does not support XMLHTTP.");
                }
            }
            
            function state_Change(){
				// 4 = "loaded"
                if (xmlhttp.readyState == 4) {
					// 200 = "OK"
                    if (xmlhttp.status == 200) {
                        document.getElementById('T1').innerHTML = xmlhttp.responseText;
                    }
                    else {
                        alert("Problem retrieving data:" + xmlhttp.statusText);
                    }
                }
            }
        </script>
    </head>
    <body onload="loadXMLDoc('test.html')">
        <div id="T1" style="border:1px solid black;height:40;width:300;padding:5">
        </div>
        <br/>
        <button onclick="loadXMLDoc('test.html')">
            Click
        </button>
    </body>
</html>
?