2010-01-07 137 views
0

我似乎無法找出這個問題,由於某些原因我的代碼片段(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"); 
      } 
     }); 

    }); 
}); 
+1

請發佈您的jQuery代碼用於調用該函數。 – 2010-01-07 05:03:27

回答

1

在JavaScript中,你要getRatingText()第一個電話是不正確的(在getRating()函數內部的調用):

$("#rating-text").text(getRatingText()); 

您在實際執行這一點,因爲你的方法不返回任何內容:

$("#rating-text").text(undefined); 

將該行更改爲:

getRatingText(); 
+0

這沒有用,也許我誤解了你的答案? – Jawa 2010-01-07 05:16:55

+0

我想通了,但另一個問題出現謝謝。 – Jawa 2010-01-07 05:46:19