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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助