var mouse = []; $(function() { $(document).mousemove(function(e) { mouse.pushState([e.pageX < 0 ? 0 : e.pageX, e.pageY < 0 ? 0 : e.pageY]); }); setInterval(function() { $.post('server.php', mouse); mouse = []; }, 4000); });