- //
- function initXmlHttpRequest() {
- var xmlHttp = null;
- if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlHttp = new XMLHttpRequest();
- }else{ // code for IE6, IE5
- xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- return xmlHttp;
- }
- //
- function getServerTime() {
- var xmlHttp = initXmlHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 2) {
- document.write(new Date(xmlHttp.getResponseHeader("Date")));/*TODDO: Show the date to html.*/
- }
- }
- xmlHttp.open("GET", "null.txt", true);
- xmlHttp.setRequestHeader("Range", "bytes=-1");
- xmlHttp.setRequestHeader("If-Modified-Since", "q");
- xmlHttp.send();
- }
- //该片段来自于http://www.codesnippet.cn/detail/2511201514080.html
来源: http://www.codesnippet.cn/detail/2511201514080.html