赋值给ends,显示不出来,哪里错了?代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p id="time"></p>
</body>
<script>
var ends;
ajax()
function ajax(option){
var xhr = null;
if(window.XMLHttpRequest){ xhr = new window.XMLHttpRequest(); }
else{ xhr = new ActiveObject("Microsoft") }
// 通过get的方式请求当前文件
xhr.open("get","/");
xhr.send(null);
// 监听请求状态变化
xhr.onreadystatechange = function(){
var time = null,
curDate = null;
if(xhr.readyState===2){
// 获取响应头里的时间戳
time = xhr.getResponseHeader("Date");
console.log(xhr.getAllResponseHeaders())
curDate = new Date(time);
ends=curDate.getTime();
}
}
}
document.getElementById('time').innerHTML=ends;
</script>
</html>
Caballarii
相关分类