Ben orada Firefox'ta döküm hiç oy ancak bazı bana nasıl gösterebilir eğer Internet Explorer merak ediyordum değilse kod benim parça (no votes cast)
görüntülenir nedense bu sorunu anlamaya gibi olamaz Kod iki tarayıcılarda görüntülenir bu sorunu çözmek?
Ben JQuery ve PHP kullanıyorum.
Burada PHP kodudur.
// function to retrieve average and votes
function getRatingText(){
$sql= "SELECT * FROM vote";
$result = mysql_query($sql);
$rs = mysql_fetch_array($result);
if (!empty($rs['value']) && !empty($rs['counter'])){
$avg = (round($rs['value'] / $rs['counter'],1));
$votes = $rs['counter'];
echo $avg . "/10 (" . $votes . " votes cast)";
} else {
echo "(no votes cast)";
}
}
JQuery kodu.
$(document).ready(function() {
// get current rating
getRating();
// get rating function
function getRating(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getrate",
cache: false,
async: false,
success: function(result) {
// apply star rating to element dynamically
$("#current-rating").css({ width: "" + result + "%" });
// add rating text dynamically
$("#rating-text").text(getRatingText());
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
// get average rating
getRatingText();
// get average rating function
function getRatingText(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getavgrate",
cache: false,
async: false,
success: function(result) {
// add rating text
$("#rating-text").text(result);
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
// link handler
$('#ratelinks li a').click(function(){
$.ajax({
type: "GET",
url: "update.php",
data: "rating="+$(this).text()+"&do=rate",
cache: false,
async: false,
success: function(result) {
// remove #ratelinks element to prevent another rate
$("#ratelinks").remove();
// get rating after click
getRating();
},
error: function(result) {
alert("some error occured, please try again later");
}
});
});
});