I am trying to replicate this demo with my own remote data source:
http://demos.jquerymobile.com/1.4.5/listview-autocomplete-remote/
My HTML page is exactly the same as the demo with one difference:
url: "http://localhost/sample.php",
And here's my dummy remote data source sample.php
<?php
$a = array('apple', 'mango');
echo json_encode($a);
What could be missing here? Since my dummy data is just a simple array, I am expecting that it will autocomplete with "apple", "mango"
but nothing appears.
Edit: I tried the following, still doesn't work:
<?php
$a = array("apple", "mango");
header('Content-Type: application/javascript; charset=utf-8');
echo $_GET['callback'].'('.json_encode($a).');';
The "View source" actually lies. There's a missing line in HTML as next JS $( document ).on( "pagecreate", "#myPage", function() {
expects #myPage
. Thus, HTML should look this way:
<body>
<!-- this div was missing -->
<div data-role="page" id="myPage">
<h3>Cities worldwide</h3>
<p>After you enter <strong>at least three characters</strong> the autocomplete function will show all possible matches.</p>
<form class="ui-filterable">
<input id="autocomplete-input" data-type="search" placeholder="Find a city...">
</form>
<ul id="autocomplete" data-role="listview" data-inset="true" data-filter="true" data-input="#autocomplete-input"></ul>
</div>
</body>
So if you add that missing div <div data-role="page" id="myPage">
and use next php code, then everything will work fine:
<?php
header('Content-Type: application/javascript; charset=utf-8');
$callback = $_GET['callback'];
$q = $_GET['q'];
$json = json_encode(['apple', 'mango']);
echo "$callback($json);";
?>
Just in case, these are 2 files I used in my test:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.