- 第一种
var xhr = new XMLHttpRequest();
if( !xhr ){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("HEAD",location.href,true);
xhr.onreadystatechange=function(){
if( xhr.readyState == 4 && xhr.status == 200){
console.log(xhr.getResponseHeader("Date"));
}
}
xhr.send(null);
打印:
Wed, 21 Oct 2020 10:01:29 GMT
- 第二种
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'https://quan.suning.com/getSysTime.do', true);
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequest.send(null);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var json = httpRequest.responseText;
console.log(json);
}
};
打印:
{"sysTime2":"2020-10-22 12:28:35","sysTime1":"20201022122835"}
2022年8月3日 更新接口 http
更改为https