dongyanju1094 2010-01-07 04:59
浏览 33
已采纳

PHP和IE浏览器显示问题

I can't seem to figure out this problem for some reason my piece of code (no votes cast) will be displayed if there are no votes casted in Firefox but not in Internet Explorer I was wondering if some can show me how to fix this problem so the code is displayed in both browsers?

I'm using JQuery and PHP.

Here is the PHP code.

// 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 code.

$(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条回答 默认 最新

  • dpquu9206 2010-01-07 05:09
    关注

    In the JavaScript, your first call to getRatingText() is incorrect (The call inside the getRating() function):

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

    You are actually executing this because your method does not return anything:

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

    Change that line to just:

    getRatingText();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?