Hello, everyone.
I'm trying to create a project, whose function is to identify how long the page is open (ie if it's been 1 or 2 minutes open). When it is closed, save the time information in the database.
However, I'm a denial with javascript, jquery, and the like. Here is sample code:
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script><script>varaberturaPagina;$(window).ready(function(){aberturaPagina=newDate().getTime();});$(window).on('beforeunload',function(){varfechoPagina=newDate().getTime();vartempoAberto=(fechoPagina-aberturaPagina)/1000;$.ajax({type:"POST",
url : "http://url.exmplo.com.br/codigo_db.php?id=1&tempo=" + tempoAberto,
sucess : function(html){
$('.div').html(html);
}
})
});
</script>
When you run the page, nothing happens!
I've set up this frankenstein with codes from some forums, can anyone help me fix it?