Last active
October 23, 2015 02:37
-
-
Save viko16/9895873 to your computer and use it in GitHub Desktop.
ajax获取服务器时间 #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var something = "http://www.baidu.com"; //任意同域资源,size越小越好 | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.open("GET", something, false); | |
xmlhttp.send(); | |
console.log("服务器时间:" + new Date(xmlhttp.getResponseHeader("date"))); //自己解析响应头,不一定是"date"的 | |
console.log("本机的时间:" + new Date()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with(new XMLHttpRequest) { | |
open("GET", "/"); | |
onreadystatechange = function(){ | |
if(readyState >= 2 && getResponseHeader('Date')){ | |
console.log(getResponseHeader('Date')) | |
abort(); | |
} | |
} | |
send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notice
ie
的情况post
还是get
自己改date