This is going to seem kind of crazy, but I'm trying to create some javascript that will update the hits count of a listing whenever I click on a link. So far, this is what I've coded, but I don't know how to debug it to make it work. (nor do I know much about coding any of this stuff)
Beginning with the theme file, an onclick call to addHits:
<span class="jrButton" title="<?php __t("Increase Hits");?>" onclick="jreviews.listing.addHit(this,{'listing_id':'<?php echo $listing['Listing']['listing_id'];?>'})"> hit++ </span>
In jreviews.js, a jQuery call to _hitsAdd:
addHit: function(element,options)
{
jQuery(element).s2SubmitNoForm('listings','_hitsAdd','data[listing_id]='+options.listing_id);
},
In everywhere_com_content.php, which calls hitMe:
function _hitsAdd()
{
$listing_id = Sanitize::getInt($this->data,'listing_id');
$res = $this->Listing->hitMe($listing_id);
if($res['success'])
{
return json_encode(array('error'=>false));
}
return $this->ajaxError(s2Messages::submitErrorDb());
}
In listings_controller.php, where the database is updated:
function hitMe($listing_id)
{
$listing_id = (int) $listing_id;
$result = array('success'=>false,'hits'=>null);
if(!$listing_id) return $result;
$query = "
SELECT
Listing.hits
FROM
#__content AS Listing
WHERE
Listing.id = " . $listing_id
;
$this->_db->setQuery($query);
$data['Listing']['id'] = $listing_id;
$data['Listing']['hits'] += $result['hits'];
if($this->store($data,false,array()))
{
// Clear cache
clearCache('', 'views');
clearCache('', '__data');
$result['success'] = true;
};
return $result;
}
Currently, the error message I'm getting is:
Uncaught TypeError: Object [object Object] has no method 's2SubmitNoForm' jreviews.js:427
I'm not really expecting a response, but has anyone done a customization of the ajax/javascript code like this?