博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

javascript 获取服务时间

Posted on 2017-06-02 11:46  绝交  阅读(122)  评论(0编辑  收藏  举报

用到了jquery的ajax方法,ajax自己写也可以。

具体用法

 

var setId = setInterval(function(){
var xhr = $.ajax({
type: 'HEAD', // 获取头信息,type=HEAD即可
url : window.location.href,
complete: function( xhr,data ){
var date = new Date(xhr.getResponseHeader('Date'))
console.log(date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate() +' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds())
// if(date.getHours()==14 && date.getMinutes()>=0 && date.getSeconds()>=0){
// // clearInterval(setId)
// }
}
})
},1000)

 

ajax生命周期

// 1.ajaxStart(全局事件)
// 2.beforeSend
// 3.ajaxSend(全局事件)
// 4.success
// 5.ajaxSuccess(全局事件)
// 6.error
// 7.ajaxError (全局事件)
// 8.complete
// 9.ajaxComplete(全局事件)
// 10.ajaxStop(全局事件)