Проблемы с отображением в браузерах PHP и IE - PullRequest
0 голосов
/ 07 января 2010

Я не могу понять эту проблему по какой-то причине, мой кусок кода (no votes cast) будет отображаться, если в Firefox нет голосов, но не в Internet Explorer. Мне было интересно, могут ли некоторые показать мне, как исправить эта проблема, поэтому код отображается в обоих браузерах?

Я использую 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 Ответ

1 голос
/ 07 января 2010

В JavaScript ваш первый вызов getRatingText() неверен (вызов внутри функции getRating()):

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

Вы на самом деле выполняете это, потому что ваш метод ничего не возвращает:

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

Измените эту строку на просто:

getRatingText();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...