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 回答