To remote data source and liswiew
wrap the ul element with a div
<div data-role="page" id="myPage">
<form id="myform" class="ui-filterable">
<input id="what" data-type="search" placeholder="i.e.Carpentry...">
<div id="w_what">
<ul id="ul_what" data-role="listview" data-inset="true" data-filter="true" data input="#what">
</ul>
</div>
</form>
</div>
$( "#ul_what" ).on( "filterablebeforefilter", function ( e, data ) {
var $ul = $( this ),
$input = $( data.input ),
value = $input.val(),
html = "";
$ul.html( "" ); // initially null
$('#w_what').show(); // For next search
if ( value && value.length > 0 ) {
$ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
$ul.listview( "refresh" );
$.ajax({
url: "/php/getWhat.php", // Ajax url
dataType: "json", // json
data: {
q: $input.val() // which value to be searched
}
})
.then( function ( response ) {
$.each( response, function ( id, val ) {
html += "<li>" + val.text + "</li>"; // json response has text element
});
$ul.html( html );
$ul.listview( "refresh" );
$ul.trigger( "updatelayout");
});
}
});
$('#ul_what').delegate('li', 'click', function () {
var ul = $(this); // when clicked
$('#what').val(ul.text()); // set the value for input
$('#w_what').hide(); // hide the div
});
Hope helps to somenone