私は非常に単純なスクリプトを作成しようとしています。これは、サイトにログインしたままにし、10 分間非アクティブになるとセッションを削除します。これは、次のように非常に簡単です。
//Silently "refresh" the page - at least server thinks you refreshed, thus you're active
function call() {
var req = new XMLHttpRequest();
//Load current url
req.open("GET",location.href,true);
//Try to only send the data! (does not work - the browser also receives data)
req.onprogress = function() {
this.abort(); //Abort request
wait(); //Wait another 5 minutes
}
//Repeat request instantly if it fails
req.onerror = call;
//Send
req.send();
}
function wait() {
//5minutes timeout
setTimeout(call,5000);
}
wait();
これは完全に機能しますが、リクエストは完全にロードされているようです。ページは小さいですが、これをきれいにして、データのダウンロードを防ぎたいです。つまり、データのダウンロードが開始されたらすぐに読み込みを停止したいということです。またはより良い-データが送信された後。
そのような「ping」機能を作成する方法はありますか?