세션 시간이 초과되기 전에 문제를 일으키는 몇 가지 큰 양식이 있습니다. 페이지가 열려있는 한 세션 제한 시간을 새로 고치는 데 몇 분마다 파일을 ping하기 위해 페이지 끝 부분에 작은 자바 스크립트가 필요합니다. 그래서 나는 마지막 문이 함수를 갭 이후에 다시 호출하는 함수를 가지고있다. 또한, jQuery와 다른 프레임 워크를 사용할 수없는 여러 가지 이유가 있습니다. 그래서 나는 그래서 하트 비트 분마다 실행해야합니다 60000을 반환 https://stackoverflow.com/a/35970894/385011내 심장 박동이 시간 초과 값에 대해 일시 중지되지 않았습니다.
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "json";
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
callback(null, xhr.response);
} else {
callback(status);
}
};
xhr.send();
};
//hearbeat
function heartbeat(heartbeaturl){
getJSON(heartbeaturl,function(err, data) {
console.log(Date.now());
console.log(data.time);
setTimeout(heartbeat(heartbeaturl), data.time);
});
}
console.log("run heartbeat");
heartbeat("heartbeat.json")
data.time에서 이것을 함께 넣어 가지고 있지만, 매 1 ~ 4ms의 실행 죄. 내가 뭘 놓치고 있니?
setTimeout(function() {
heartbeat(heartbeaturl);
}, data.time)
는 달리 heartbeat(heartbeaturl)
에 도달 할 data.time 기다리지 않고 즉시 실행됩니다
Akternative 새로운 익명 함수를 만드는가에'setTimeout'과 같이 매개 변수를 전달하는 것입니다. 지연 후에는 실행 된 후에 지연된 함수로 전달됩니다. – vlaz