CodeIgniter Forums
onUnload event -> session_destroy() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: onUnload event -> session_destroy() (/showthread.php?tid=36255)



onUnload event -> session_destroy() - El Forum - 11-26-2010

[eluser]Fribos[/eluser]
Hi!
I need to execute a function for session destroy when the user leaves, using onunload javascript event.
I'm codding something like this:

On my controller
Code:
function destruir_sesion(){
        //destruyo sesion
        $this->session->sess_destroy();
    }

On my <head> view
Code:
function destruir_sesion(){
       if (document.location.href=='xxxxxxxxxxxx/chatfinal') {
            $.ajax({
              type: "POST",
              url: "xxxxxxxxxxxx/chatfinal/destruir_sesion",
              success: function (result) {
              }
            });
       }
    }

On my view body div
Code:
onunload="destruir_sesion()"

I cant understand AJAX sintax, so if u can help me i'll thank you.
Where can i find a good ajax tutorial for begginers ?
Thanks


onUnload event -> session_destroy() - El Forum - 11-26-2010

[eluser]vitoco[/eluser]
this tutorial it's very simple, also cover javascript fundamentals
http://jqfundamentals.com/book/book.html

Saludos