当发生汇款时,如果浏览器关闭,会发生什么?我的意思是,当我在服务器上进行处理时,然后在提交所有更改之前,我要检查客户端是否仍然在线。如果突然关闭浏览器,则撤消更改。
我的代码是这样的:
function some(){
do_some_stmt;//also keep track what changes has been done
do_some_stmt;//also keep track what changes has been done
...............
if(connection_is_still_alive()){
// final commit
}else{
undo_the_previous_changes();
}
}
因此,您可以用php,java回答,我认为如果可能的话,那么在为客户端-服务器体系结构设计的每种编程语言上都可以实现。
基本上,我想知道在脚本中间是否可以检查浏览器是否仍然在线?
任何建议都值得欢迎,并预先感谢您让我理解。
您可以制作一个javascript函数,该函数会定期加载PHP页。
像这样的东西:
创建3个文件:file.js,onlinecheck.php和log.txt
file.js:
function tellTheServerThatIAmStillHere() {
$.post('onlinecheck.php', {onlineStatus: iAmStillHere}); /* Sends a post to the file onlinecheck.php with the parameter "onlineStatus: iAmStillHere" */
timer = window.setTimeout(tellTheServerThatIAmStillHere,8000); /* sends a new post every 8 seconds */
}
onlinecheck.php:
<?php
if(isset($_POST["onlineStatus"])) {
if($_POST["onlineStatus"] == "iAmStillHere") {
$fd = fopen("log.txt", "w");
fwrite($fd, date("[d.m.Y - H:i:s] ").$_SERVER['REMOTE_ADDR'].": He is still here"); //Puts out something like "[26.03.2014 - 13:57:33] 127.0.0.1: He is still here"
fclose($fd);
}
}
现在,您可以在日志文件中检查浏览器是否仍处于在线状态,这就是您的意思。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句