SAPO::Component.Rating - Demo


.: 1 - (current rating: 60) :.


.: 2 (current rating: 30) - can not rate (ex: user is not logged) :.


.: 3 (current rating: N/A) :.


Server side - HowTo

PHP


<?php
/**
 * GET variables defined in your SAPO::Component.Rating options 
 */
$rate = intval($_POST['rate']);
$identifier = $_POST['hash'];

/**
 * Then, with that values, calculate your new rating and define your ajax response 
 */
$rand = mt_rand(0,100); // value _MUST_ be between 0 - 100 (I use rand just to test it)

echo '{"rating":"'.$rand.'", "message": "Thanks :)"}';

?>

Perl


<%perl>
#
# GET variables defined in your SAPO::Component.Rating options 
#

my $rate = %ARGVS{'rate'};
my $identifier = %ARGS{'hash'};

#
# Then, with that values, calculate your new rating and define your ajax response 
#
my $rand = int(rand(100)); // value _MUST_ be between 0 - 100 (I use rand just to test it)
</%perl>

{"rating": "<% $rand %>", "message": "Thanks :)"}';

.NET


<%
/**
 * GET variables defined in your SAPO::Component.Rating options 
 */

int rate = 0;
int rand = 0;
string hash = "";

if (!int.TryParse(HttpContext.Current.Request["rate"], out rate))
{
    rate = 0;
}

hash = HttpContext.Current.Request["hash"];

/**
 * Then, with that values, calculate your new rating and define your ajax response 
 */

rand = 30; // do stuff to calculate this variable ( _MUST_ be between 0 - 100 )

Response.Write("{\"rating\": \""+rand+"\", \"message\": \"Thanks\"}");
%>