1

我正在尝试在 jquery 移动网站(http://view.jquerymobile.com/1.3.2/dist/demos/widgets/autocomplete/autocomplete-remote.html)上使用 php 文件获取 Jquery 移动自动完成演示,如果我在 firebug 中测试,我的回调响应以这种格式工作: [{"label":"278","value":"ANGELIC HOISTIC HEALING"}] 但我不知道为什么没有显示任何结果在我的 html 上,代码如下:

<script type="text/javascript">
$( document ).on( "pageinit", "#searchPage", function() {
$( "#autocomplete" ).on( "listviewbeforefilter", function ( e, data ) {
    var $ul = $( this ),
        $input = $( data.input ),
        value = $input.val(),
        html = "";
    $ul.html( "" );
    if ( value && value.length > 2 ) {
        $ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
        $ul.listview( "refresh" );
        $.ajax({
            url: "services/search2.php",
            dataType: "jsonp",
            crossDomain: true,
            data: {
                term: $input.val()
            },

        })
        .then( function ( response ) {

            $.each( response, function ( i, val ) {
                html += "<li>" + val.value + "</li>";
            });
            $ul.html( html );
            $ul.listview( "refresh" );
            $ul.trigger( "updatelayout");
        });
    }
});

});

php:

(database connection)
$q = strtolower($_GET["term"]);

$return = array();
$query = mysql_query("select * from directory2 where business like '%$q%'");
  while($row = mysql_fetch_assoc($query)) 
  {
      array_push($return, array(
        'label'      => $row['ID'], 
        'value'    => html_entity_decode($row['business'], ENT_QUOTES, 'UTF-8') )
    );
  }     

echo(json_encode($return));

html

<div data-role="content">
<h3>Cities worldwide</h3>

输入至少三个字符后,自动完成功能将显示所有可能的匹配项。

<<ul id="autocomplete" data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Find a business..." data-filter-theme="d"></ul>

</div>


请任何帮助将不胜感激,我一直在到处寻找这个,但没有运气!

4

0 回答 0