I'm trying to populate a listview of jQueryMobile with contents from PHP side.
load_info.php file have the following code:
if(isset($_GET['type'])){
switch($_GET['type']){
case 'locale':
load_locale("localhost", "root", "", "testing");
break;
}
}
function load_locale($host, $user, $pass, $db){
$db = new mysqli($host, $user, $pass, $db);
$db->set_charset("utf8");
$query = $db->prepare("SELECT `desc` FROM locale");
$query->execute();
$query->bind_result($desc);
$query->store_result();
$rows = array();
while($query->fetch()){
$rows[] = array("value" => $desc);
}
$query->close();
$db->close();
return json_encode($rows);
}
And in the index.php page, I have the following:
<div data-role="page" id="page-locale">
<div data-role="header" data-theme="b" data-close-btn="right">
<h1>Locale</h1>
</div>
<div data-role="content" id="content">
<ul id="listview_locale" data-role="listview" data-inset="true" data-filter="true" data-autodividers="true" data-filter-placeholder="Search..">
</ul>
</div>
</div>
<script type="text/javascript">
$(document).on("pagebeforeshow", "#page-locale", function() {
$(function(){
var items = "";
$.getJSON("load_info.php?type=locale",function(data){
$.each(data, function(index, item)
{
items += "<li>" + item.value + "</li>";
});
$("#listview_locale").html(items);
$("#listview_locale").trigger("change");
$("#listview_locale").trigger("refresh");
});
});
});
</script>
Although, when I click the button to go to the page id #page-locale, the listview has nothing. I don't receive any error, but also it has no content.
What is wrong?
Edit: Solved. Instead of
$.getJSON("load_info.php?type=locale", function(data){
must be
$.getJSON("classes/load_info.php?type=locale", function(data){
instead of
load_locale("localhost", "root", "", "testing");
must be
echo load_locale("localhost", "root", "", "testing");