开发者

Process a file when user exits page?

this is my code so far, what I'm trying to do is process the io_up.php file when the user leaves the page. It was also be great if i could pause the page load for 3sec afte开发者_如何学编程r file is processed.

<script type="text/javascript"> 
function setConfirmUnload(on) {
    Window.onbeforeunload = (on) ? unloadMessage : null;
}

function unloadMessage() {

    $.ajax({
       async: true,
       url: "/proc_files/io_up.php",
       success: function(msg){
         alert( "Data Saved.");
       }
     });

}
</script>


Change the code to synchronous instead of async. Just remember that you are doing to hang the user's browser.

This code will be called when people leave the page, refresh it, click a link, etc. Is that what you really want?

You really should be handling this with sessions on the server and not relying on the client. Browser errors, people putting their computers to sleep, network errors, etc will never fire your processing code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜