I am using this rateyo plugin in my application. There is a page where user can give rating to an entity. But before giving rating I am making a check, if that user already assigned a rating to that particular entity and if the user does, then I fetch rating value from database and set it as the plugin says. But if it is a new user, he can submit his new rating.
here is the code what I am implementing:
$(document).ready(function(){
$("#rateYo").rateYo().on('rateyo.set',function(e, data){
$.ajax({
type : "post",
url : "PostRatingValue.php",
data : {
"rating" : data.rating,
"peopleid" : celeb_id,
"userid" : user_id
},
dataType : "json",
success : function(response){
if(response.toString() == "true"){
$.growl.notice({ title: "Growl", message: "Rating<b> "+ data.rating +" </b>assigned successfully" });
}
else{
$.growl.error({ message: "<b>Unable to assign rating.</b>" });
}
},
error : function(response){
$.growl.error({ message: "<b>Something went terribly wrong! :'(.</b>" });
}
});
});
below is the code to set the rating value if it exist.
<?php
if(isset($fetchRatingIdAndValue['ratingpoints'])){
?>
$("#rateYo").rateYo("option", "rating", <?php echo $fetchRatingIdAndValue['ratingpoints'];?>);
<?php
}
?>
});
Problem is that, when old rating is set, an ajax call is made which inserts same data again in table. I want my ajax call to work only when I need to set new rating or edit previous rating. I am not able to find the way out for this. Please help.