我正在尝试使用 jquery ui 自动完成和 json 自动完成字段,来自 php 文件的数据......但无法得到任何结果......
这是我的jQuery代码:
$('#rech_abo').keyup(function(e) {
e.preventDefault();
$( ".find_group_ac" ).autocomplete({
minLength: 3,
source: function(request, response) {
$.ajax({
url: "/chercheabo",
data: {achercher : $("#rech_abo").val()},
dataType: "json",
type: "POST",
success: function(data) {
response($.map(data, function(obj) {
return {
label: obj.pseuDO,
value: obj.userID,
// description: obj.description
// id: obj.userID // don't really need this unless you're using it elsewhere.
};
}));
}
});
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
// Inside of _renderItem you can use any property that exists on each item that we built
// with $.map above */
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "<br>" + item.description + "</a>")
.appendTo(ul);
};
});
我的PHP:
$options = array();
$result = mysqli_query($link,"select userid, pseudo from utilisateurs where pseudo like '%".strtolower($_POST[achercher])."%'");
while($uti = $result->fetch_object()) {
$options['myData'][] = array(
'userID' => $uti->userid,
'pseuDO' => $uti->pseudo,
'retourDATA' => $retour_data
);
}
echo json_encode($options);
还有我的html:
<div class=\"abo_parnom\"><input class=\"input_text_compte\" type=\"text\" placeholder=\"Tappez un nom\" id=\"rech_abo\"> <input type=\"button\" id=\"rech_abo_valider\" class=\"bouton_suppr\" value=\"Ok\"></div>
知道这里缺少什么吗?谢谢