日期:2014-05-16 浏览次数:20492 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script type="text/javascript"> var urls = { "Button1": "/ajax/demo_get1.asp?fname=Bill&lname=Gates", "Button2": "/ajax/demo_get2.asp?fname=Bill&lname=Gates", "Button3": "/ajax/demo_get3.asp?fname=Bill&lname=Gates", "Button4": "/ajax/demo_get4.asp?fname=Bill&lname=Gates" }; function loadXMLDoc(t) { alert(urls[t.id]); var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", urls[t.id], true); xmlhttp.send(); } </script> </head> <body> <h2>AJAX</h2> <button type="button" id="Button1" onclick="loadXMLDoc(this)">请求数据</button> <button type="button" id="Button2" onclick="loadXMLDoc(this)">请求数据</button> <button type="button" id="Button3" onclick="loadXMLDoc(this)">请求数据</button> <button type="button" id="Button4" onclick="loadXMLDoc(this)">请求数据</button> <div id="myDiv"></div> </body> </html>