Ok, I installed a component for my Joomla but now I'm working for add a custom counter views.
In controller.php of the component I added the following functions:
function updateView() {
$db = JFactory::getDBO();
$videoid = JRequest::getVar('videoid');
if ($videoid) {
$query = "update #__hdflv_upload SET times_viewed=1+times_viewed where id=$videoid";
$db->setQuery($query);
$db->query();
}
$query = "select times_viewed from #__hdflv_upload where id=$videoid";
$db->setQuery($query);
$timeView = $db->loadResult();
echo $timeView;
jexit();
}
Anyway, in the page I tried to call this function with php and works fine, but with cache enabled the script stop working. They said to me that in Joomla the counter views should always be in Ajax. But I'm that expert on Ajax, I tried with this but with no result:
<script>
$.ajax({
url: 'index.php?option=com_contushdvideoshare&task=updateView&format=raw',
success: function(data){
if(!data.length){
// Throw an error
return;
}
$('.container').html(data);
}
});
</script>
Can somebody help me? Thank you