0

10秒ごとに更新されるdivを含むphpファイルを作成しました。この div では、クエリの結果が読み込まれます。デモ: http://mauricederegt.nl/test/test.php

Divが更新されているように見えますが、データベースに新しいデータが追加された場合、DIVは新しいデータを取得せず、古いデータを表示し続けます。

リロードが必要なページと同じページを使用します。

$('#scoreboard-overview').fadeOut('slow').load('index.php #scoreboard-overview').fadeIn("slow");

div で使用されている sql クエリを外部の php ファイル (reload.php など) にコピーしてから、次のように呼び出します。

$('#scoreboard-overview').fadeOut('slow').load('reload.php').fadeIn("slow");

それは機能し、div は最新のデータを示します。問題は、別の外部 php ファイルを使用したくないということです。

どうすればこれを達成できますか?

また、クエリをdivに入れようとしました$resultttが、これも効果がありませんでした。私は何が欠けていますか?

敬具、

index.php で使用されるコード:

<?php
    /////////////////////////////////////////////

    //mysql_connect(servername,username,password);
    //Here we connect to the database

    /////////////////////////////////////////////
//Get the data
$resulttt = mysql_query("SELECT fbID, highscore, stars, MIN(time) AS time FROM highscore GROUP BY fbID, highscore ORDER BY highscore DESC, time ASC LIMIT 7");



?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">

<head>
<meta charset="utf-8">
<title>Test</title>
<link rel="stylesheet" href="test.css" />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$('#scoreboard-overview').fadeOut('slow').load('index.php #scoreboard-overview').fadeIn("slow");
}, 10000);
</script>
</head>
  <body>
    <div id="scoreboard">
        <div id="scoreboard-title">High scores</div>
        <div id="scoreboard-overview">
        <?php   echo '<ul>';
                $num_rows = mysql_num_rows($resulttt);
                $i = 0;
                    while($row = mysql_fetch_array($resulttt)) {
                        $i = $i + 1;
                        $fb_data = json_decode(file_get_contents('http://graph.facebook.com/'. $row['fbID']));
                        $fb_locale_str = $fb_data->locale;
                        $fb_name_str = $fb_data->first_name;
                        $fb_country_str = strtolower(substr($fb_locale_str, -2));
                        $flag_uri = 'images/flags/unknown.gif'; //display a general flag if unknown.
                        $row['fbnr'] = $row['fbID'];

                        echo '<li id="'. $row['fbnr'] .'">
                                <div class="userpicture"><img src="https://graph.facebook.com/'. $row['fbID'] .'/picture" alt="" /></div>
                                <div class="username"><p>'.$i.'. '.$fb_name_str.'</p></div>
                                <div class="userflag"><img src="'.$flag_uri.'" alt="" /></div>  
                                <div class="userholder">
                                    <div class="usertime"><p><img src="images/time.png" alt="" /><br>'. $row['time'] .'</p></div>
                                    <div class="userstars"><img src="images/'. $row['stars'] .'s.png" alt="" /></div>
                                    <div class="userscore"><p>'. $row['highscore'] .'</p></div>
                                </div>      
                            </li>';
                    }
            echo '</ul>'; ?>

        </div>
        <div id="scoreboard-bottom">end</div>
    </div>
  </body>
</html>

を使用して回避策を見つけたと思います。GET助けてくれてありがとう

4

1 に答える 1

2

<html>JavascriptがHTMLページ全体( 、、<head>および<body>タグを含む)を既存のドキュメントの要素に挿入しようとすることに満足するブラウザは想像できません。scoreboard-overviewロードされたページのコンテンツをscoreboard-overview既存のページに配置したいので、次の呼び出しにセレクターを追加します.load()

$('#scoreboard-overview').fadeOut('slow').load('index.php #scoreboard-overview').fadeIn("slow");
于 2012-06-07T15:19:42.343 に答える