1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>Ajax应用:异步获取历史上的今天</title> <script language="javascript"> //Ajax远程获取滚动条样式 var http_request = false; function makeRequest(url) { http_request = false; //Loading提示: document.getElementById("historyText").innerHTML = "正在读取…"; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType("text/xml"); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { document.getElementById("historyText").innerHTML = "无法创建XMLHTTP实例!"; //alert("Giving up :( Cannot create an XMLHTTP instance"); return false; } d = new Date(); // 创建 Date 对象。 s = "temp"; s += d.getYear(); // 获取年份。 s += d.getMonth() + 1; // 获取月份。 s += d.getDate(); // 获取日。 s += d.getHours(); // 获取小时。 s += d.getMinutes(); // 获取分钟。 s += d.getSeconds(); // 获取秒数。 url = "todayOnHistory_Proxy.asp?tempVar=" + s; http_request.onreadystatechange = alertContents; http_request.open("GET", url, true); http_request.send(null); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { document.getElementById("historyText").innerHTML = http_request.responseText; } else { document.getElementById("historyText").innerHTML = "数据读取失败!"; } } } </script> <style type="text/css"> body,td{font-size:14px;color:#000000;} a:link,a:visited{font-size:14px;color:#000000; text-decoration:underline} a:hover{font-size:14px;color:#0046D5; text-decoration:underline} .style22{ width: 800px; height: 100px; margin: 0px auto; margin-bottom:20px; border:1px solid #DEDEB8; background-color: #FDFFF2 } </style> </head> <body onload="makeRequest()"> <fieldset style="width:400px"> <legend>Today on history:</legend> <div id="historyText" style="padding:10px"> </div> </fieldset> </body> </html> |