【发布时间】:2015-12-26 20:07:59
【问题描述】:
好的,我为我的 Joomla 安装了一个组件,但现在我正在努力添加自定义计数器视图。
在组件的controller.php中我添加了以下函数:
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();
}
无论如何,在页面中我尝试使用 php 调用此函数并且工作正常,但启用缓存后脚本停止工作。他们对我说,在 Joomla 中,反视图应该始终在 Ajax 中。但我是 Ajax 方面的专家,我试过这个但没有结果:
<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>
有人可以帮助我吗?谢谢
【问题讨论】: