有人可以用我的腳本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