0
我在我的應用程序中使用了這個rateyo插件。有一個用戶可以給實體評級的頁面。但在給予評級之前,我正在進行檢查,如果該用戶已經爲該特定實體分配了評級,並且該用戶確實給予了評級,那麼我從數據庫獲取評級值並將其設置爲該插件所述。但如果是新用戶,他可以提交新的評分。使用rateyo插件設置數據庫評級值
這裏是我實現的代碼:
$(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>" });
}
});
});
下面
是設置評價值,如果它存在的代碼。
<?php
if(isset($fetchRatingIdAndValue['ratingpoints'])){
?>
$("#rateYo").rateYo("option", "rating", <?php echo $fetchRatingIdAndValue['ratingpoints'];?>);
<?php
}
?>
});
問題是,當設置舊的評級時,會進行ajax調用,該調用將在表中再次插入相同的數據。我只希望我的ajax調用只在需要設置新評級或編輯以前的評級時才能使用。我無法爲此找到出路。請幫忙。