我正在尝试使用jquery ui autocomplete和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>
知道这里缺少什么吗? 感谢