有人可以用我的脚本Ajax帮助我吗?我想算访问者在我的网站上花费的时间和变量发送到PHP页面:使用AJAX计算访问者在我的网站上花费的时间
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
var start;
$(document).ready(function() {
start = Date.getTime();
$(window).unload(function() {
end = Date.getTime();
$.ajax({
url: 'timer.php',
type:'POST',
async: false,
data: {
'timeSpent': end - start,
x:'hello'
}
})
});
}
和timer.php我把:
了参考http://stackoverflow.com/questions/4667068/how-to-measure-a-time-spent-on-a-page – Dhara