I’m working on just basic stats for how long someone is on a page, these are sent via JavaScript to the controller, but I’m struggling to extract the values.
How exactly does it send teh data.
<script>
var timeStarted, a, b, c, timeLeft, pageData;
timeStarted = new Date().getTime();
a = 1;
b = 2;
c = 3;
window.onbeforeunload = function()
{
timeLeft = new Date().getTime();
pageData = [timeStarted, a, b, c, timeLeft];
// Set url for JavaSCript
var url = '/localhost/item/viewedItem';
<?php echo CHtml::ajax(array(
'url'=>'js:url',
'data'=> "js: $(pageData).serialize()",
'type'=>'post',
'dataType'=>'json',
)) ?>;
}
</script>
Then within the controller I just don’t know how i’d access the results. I’ve tried just
$pageData = CJSON::encode($_POST);
$viewed->a = $pageData[‘a’];