我从mySQL和php填充listview,但是当响应文本回退到html时,它显示为纯文本,而不是listview。 这是我的HTML代码:
<div data-role="page" id="myevents" data-theme="a">
<?php include("profileHeader.php");?>
<div data-role="main" class="ui-content" >
<div data-role="collapsible" data-collapsed="false"><h2>My events</h2>
<ul data-role="listview" id="myeventslist" data-inset="true">
</ul></div>
</div>
这是html文件中的脚本:
<script>
$(document).on("pagecreate","#myevents",function(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myeventslist").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "myeventslist.php", true);
xmlhttp.send();
});
这是我的php脚本(myeventslist.php文件):
//before this is PDO statement
$myeventslist = '';
foreach($stmtmyeventslist->fetchAll(PDO::FETCH_ASSOC) as $myeventsrow){
$myeventslist .= '<li>' . $myeventsrow['eventname'] . '</li>';
}
$db=null; // Closing Connection
} catch (PDOException $e) {
//echo $e->getMessage();
echo "Error. Try again in 15 minutes";
die();
}
echo $myeventslist;
但结果不是我的预期:(: 嘿,我没有声望等级10张贴图片
答案 0 :(得分:0)
我找到了解决方案。在html脚本块中必须包含:
$("#myeventslist").append(xmlhttp.responseText);
$("#myeventslist").listview('refresh');
而不是:
document.getElementById("myeventslist").innerHTML = xmlhttp.responseText;