I populate listview from mySQL and php, but when response text falls back in html, it shows like plain text, not listview. This is my html code:
<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>
This is script in html file:
<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();
});
And this is my php script (myeventslist.php file):
//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;
But results is not what i expected :( : heh, i have no reputation level 10 to post picture
I found a solution. In html script block must contain:
$("#myeventslist").append(xmlhttp.responseText);
$("#myeventslist").listview('refresh');
instead of:
document.getElementById("myeventslist").innerHTML = xmlhttp.responseText;