0

データベースからの結果に基づいて、動的な jquery モバイル リスト ビューを構築しようとしています。次のコードがあります。

<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug.  without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#results').load('./Display.php?id=100');
}, 3000); // the "3000" here refers to the time to refresh the div.  it is in milliseconds. 
});
// ]]></script>

<div id="results"></div>

Display.php には while ループがあります

while($row = mysql_fetch_array($query)) {
    echo "{$row['title']}
    {$row['message']}
    {$row['datetime']}
    </br>
    ";              
}

現時点では、これは .html および php ページにタイトル、メッセージ、および日時を出力するだけですが、これを次のように使用したいと考えています。

<ul data-role="listview" data-inset="true">
            <li><a href="index.html">
                <h3>Stephen Weber</h3>
                <p><strong>You've been invited to a meeting at Filament Group in Boston, MA</strong></p>
                <p>Hey Stephen, if you're available at 10am tomorrow, we've got a meeting with the jQuery team.</p>
                <p class="ui-li-aside"><strong>6:24</strong>PM</p>
            </a></li>
</ul>

これを機能させるためにいくつかの方法を試しましたが、そうではないようです.whileループコードをクリーンアップしたので、この質問の基本です. 誰かがこれを行うことができましたか?通常は<li></li>foreach を実行するだけですが、これは異なります。どんな助けでも大歓迎です。

4

1 に答える 1

0

リストビューを作成しているため、結果の div はリストビューにする必要があります...単なる div ではありません。だから私はあなたが配置することをお勧めします

<ul data-role="listview" data-inset="true" id="results">
</ul>

あなたの代わりに

<div id="results"></div>

手始めに...次に、phpはulのコンテンツをエコーする必要があります。私は次のようなことを意味します:

echo '<li><h3>'.$row['title'].'</h3><p><strong>'.$row['message'].'</strong></p></li>';    

私はそれをテストしませんでしたが、あなたはすべきです。

于 2013-07-10T10:48:07.823 に答える