2016-11-08 35 views
0

我一直在使用此代码autocompleteinput。在许多情况下,代码工作正常,但在一些情况下不。它涉及iOS用户,Android用户,Windows 7, 8, 10用户,ChromeFirefoxjquery自动完成并不总是工作

AvailabeTags包括13500房源。

感谢您的帮助;)

$("#tags").autocomplete({ 
    minLength: 3, 
    delay: 100, 
    autoFocus: false, 
    source: function (request, response) { 
    var term = $.ui.autocomplete.escapeRegex(request.term) 
      , startsWithMatcher = new RegExp("^" + term, "i") 
      , startsWith = $.grep(availableTags, function(value) { 
       return startsWithMatcher.test(value.label || value.value || value); 
      }) 
      , containsMatcher = new RegExp(term, "i") 
      , contains = $.grep(availableTags, function (value) { 
       return $.inArray(value, startsWith) < 0 && 
        containsMatcher.test(value.label || value.value || value); 
      }); 

     response(startsWith.concat(contains)); 
    }, 
    focus: function(event, ui) { 
    $("#tags").val(ui.item.value); 
    return false; 
    }, 
    select: function(event, ui) { 
    $("#{/literal}{$plzid}{literal}").val(ui.item.plz); 
    $("#{/literal}{$blid}{literal}").val(ui.item.bl); 
    return false; 
    }      
    }); 
+0

任何控制台错误,当发生这种情况? – madalinivascu

回答

0

我想你可以更好的使用PHP来处理DATAS被显示在INOUT领域

PHP代码:

的search.php

<?php 
require 'config.php'; 
$key = $_GET["term"]; 
$query = "select * from students where name like '%$key%'"; 
$result = mysqli_query($con,$query); 
while($ser=mysqli_fetch_assoc($result)){ 
    $data[] = $ser["name"]; 
} 
echo json_encode($data); 
?> 

jquery这里的代码:

<script> 
$(function(){ 
$("#name").autocomplete({ 
    source:'search.php' 
    }); 
}); 
</script> 
<input type="text" id="name"> 

注: Dont't忘了加上jQuery UI的插件