Save score in database

I am using the jQuery plugin to get a rating for a post that I made on a PHP-driven website.

The plugin I use is called Raty and can be found here .

I am wondering how I can keep this rating, because I can click on the stars and then get a rating of 5 stars, but if I refresh the page, the rating will not.

Therefore, I have to somehow save.

+3
source share
3 answers

You can try the following for the click event: (sample code)

$('#click').raty({
    click: function(score, evt) {
          $.ajax({
           type: 'POST',
           url: '/SaveMyRating.php',
           data: {'score':score},
          success: function(data){ alert('Your rating was saved'); }         
         });

    }
}); 

SaveMyRating.php should be a php script that will receive the resulting grade and save it (file or database, etc.).

+3
source

-, .

, , ( Ajax) .

+2

You can use ajax here to send the latest rating (integer) along with other necessary data to the php page. And then save the rating in the database.

// rate.php - the php page where you will insert rating.

$('#rate').raty({
    click: function(score) {
    var id = // get the id of the object for which the rating is done
        $.post('rate.php', {score:score,id:id}, function(data) {
         // data is a variable that may or may not be 
             returned from the rate.php page

            });

    }
});
+2
source

All Articles