Prototype Ajax feature helps when using Starbox plugin (star rating system)

I am using the Starbox plugin on my website and I want to post a vote value when a visitor votes using AJAX. I have read the plugin documentation and tutorials and it is possible with a function like this:

function myOnRate(element, memo) {
  new Ajax.Request('savestar.php', {
    parameters: memo,
    onComplete: function(xhr) {
      // optional callback
    }
  });
}

      

Now I know PHP, but I really don't know javascript or Prototype and I need help with this function.

I know that the "element" parameter is a rater id and that savestar.php is an external php file that will be called using AJAX .. but other than that, I have no idea what to do with it ...

I want to send the voting value to savestar.php and then I will get the value using the POST method and insert it into the database. I also need an "item" to send so that I can identify the rater.

0


a source to share


1 answer


Well ... I found the solution myself, here it is:

<script language='javascript' type='text/javascript'>

            function saveStar(event) {
                new Ajax.Request('savestar.php', {
                parameters: event.memo,
                onComplete: function(xhr) {
                    // optional callback
                }
                });
            }

            // observe just one
            document.observe('dom:loaded', function() { // once the DOM is loaded
                $('elementID').observe('starbox:rated', saveStar);
            });

            new Starbox('elementID', 8, { indicator: 'Rating: #{average} (#{total} votes)', total: 2 });

            </script> 

      



If you're reading this and just don't get it, just send me a message.

0


a source







All Articles