PHP和IE浏览器显示问题
我似乎无法解决这个问题,因为某种原因,如果Firefox中没有投票,而Internet Explorer中没有投票,我的代码将显示PHP和IE浏览器显示问题,php,jquery,Php,Jquery,我似乎无法解决这个问题,因为某种原因,如果Firefox中没有投票,而Internet Explorer中没有投票,我的代码将显示(没有投票)。我想知道是否有人可以告诉我如何解决这个问题,以便在两种浏览器中都显示代码 我正在使用JQuery和PHP 下面是PHP代码 // function to retrieve average and votes function getRatingText(){ $sql= "SELECT * FROM vote"; $result = my
(没有投票)
。我想知道是否有人可以告诉我如何解决这个问题,以便在两种浏览器中都显示代码
我正在使用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");
}
});
});
});
在JavaScript中,对
getRatingText()
的第一次调用不正确(在getRating()
函数中的调用):
您实际上正在执行此操作,因为您的方法不返回任何内容:
$("#rating-text").text(undefined);
将该行更改为:
getRatingText();
请发布用于调用函数的jQuery代码。
getRatingText();