<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XMLHttpRequest纯js实现</title>
<script language=javascript type="text/javascript">
var request = false;
function createXMLHttpRequest() {
try{
request=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
try{
request=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2){
request = false;
}
}
if (!request && typeof XMLHttpRequest != 'underfined') {
request = new XMLHttpRequest();
}
}
function getServerTime(format) {
createXMLHttpRequest();
var url = "ServerTime.aspx?format=" + escape(format);
request.open("GET", url, true);
request.onreadystatechange = update;
request.send(null);
}
function update() {
if (request.readyState == 4) {
document.getElementById("time").innerHTML = request.responseText;
}
}
</script>
</head>
<body>
<table border="0">
<tr>
<td>服务器时间</td> <td><div id="time"></div></td>
</tr>
<tr>
<td><input type="button" value="完整时间" οnclick="javascript:void getServerTime(mm-dd)" /></td>
</tr>
</table>
</body>
</html>