<!DOCTYPE html>html
<html>ajax
<head>服務器
<title>ajax</title>ui
</head>server
<body>xml
<script src="js/dui.js"></script>htm
<script>ip
// 方法一get
ajax('/', function (data, obj) {it
alert(obj.getResponseHeader("Date"));
});
// 方法二
var xmlhttp = null;
if (window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
else xmlhttp = new XMLHttpRequest();
xmlhttp.open('get', "/", false);
xmlhttp.setRequestHeader('If-Modified-Since', 'q');
xmlhttp.send();
var timestr = xmlhttp.getResponseHeader('Date');
var date = new Date(timestr);
alert(date);
</script>
</body>
</html>
var utlis = (function (win, doc) {
var module = {};
// 獲取服務器時間
module.servertime = function (options) {
var xmlhttp = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : xmlhttp = new XMLHttpRequest();
xmlhttp.open('get', '/', false);
xmlhttp.setRequestHeader('If-Modified-Since', 'q');
xmlhttp.send();
return new Date(xmlhttp.getResponseHeader('Date'));
};
return module;})(window, document);