我似乎無法找出這個問題,由於某些原因我的代碼片段(no votes cast)
將顯示,如果沒有投票在Firefox中投票,但不是在Internet Explorer中我想知道如果有人可以顯示我如何解決這個問題,以便代碼在兩個瀏覽器中顯示?PHP和IE瀏覽器顯示問題
我正在使用JQuery和PHP。
這裏是PHP代碼。
// 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代碼。
$(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");
}
});
});
});
請發佈您的jQuery代碼用於調用該函數。 – 2010-01-07 05:03:27