This is pretty straight forward.
First you need to create a controller with a specific task that processes your rating update. To ensure security, confirm the token! The token will arrive with an AJAX request.
Consider this example
function rate() {
JRequest::checkToken() or jexit('Invalid Token');
}
Second, create your AJAX request in a view explicitly called by some action. Be sure to send your request as a POST, because you are going to write data ... You can either have a script in an external document receive values ββfrom an html document (id, token, url, etc., which are in hidden inputs), or you can generate javascript with PHP and include it in your head (as in the example below).
<?php
$url = JRoute::_('index.php?option=my_component&controller=my_controller');
$token = JUtility::getToken();
$id = 101;
JFactory::getDocument()->addScriptDeclaration("
.ajax({
type: 'POST',
url: $url,
data: {
'$token': '1', // <-- THIS IS IMPORTANT
'task': 'rate',
'id': $id
},
success: youSuccessFunction
});
");
?>
, AJAX MVC.
. JRequest::checkToken('get'), URL-. AJAX, .