People, I have a code that I need to include in Wordpress. Can you please tell me how to change these codes to work in wordpress???
Non wordpress code is:
JS
$(document).ready(function() {
$('#example').ratings(5).bind('ratingchanged', function(event, data) {
$('#example-rating').text(data.rating);
$.ajax({
url : 'rating_plugin.php',
type : 'POST',
data : { rating : data.rating },
success : function(response){
console.log("successfull");
}
});
});
});
PHP
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
echo $_POST['rating']'
}
Thanks.
In wordpress in general its better to use the built in ajax functions that come with wordpress
so add the rating to your functions.php (something on these lines)
Jquery: