javascript 獲取服務時間

用到了jquery的ajax方法,ajax本身寫也能夠。jquery

具體用法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生命週期url

// 1.ajaxStart(全局事件)
// 2.beforeSend
// 3.ajaxSend(全局事件)
// 4.success
// 5.ajaxSuccess(全局事件)
// 6.error
// 7.ajaxError (全局事件)
// 8.complete
// 9.ajaxComplete(全局事件)
// 10.ajaxStop(全局事件)
相關文章
相關標籤/搜索