如何使用jquery自动完成消息应用程序的用户名? [英] How to use jquery to autocomplete with usernames for a message app?
本文介绍了如何使用jquery自动完成消息应用程序的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在玩一个小消息框,并试图在jquery UI中具有自动填充功能,但无法正常工作.没有自动填充.这就是我到目前为止所拥有的...
I'm playing around with a little message box and am trying to have an autofill feature with jquery UI but it's not working. Nothing autofills. here's what I've got so far...
composemessage.php
<script>
$(function() {
$( "#tags" ).autocomplete({
source: "usersarray.php",
dataType:'json',
minLength: 0,
delay:0
});
$( "#tags" ).click(function() {
$( "#tags" ).autocomplete("search","");
});
});
</script>
usersarray.php
$id = $_SESSION['account_id'];
$getmsg = "SELECT * FROM user WHERE account_id = $id";
$showmsg = @mysqli_query ($dbc, $getmsg);
while ($row = mysqli_fetch_array($showmsg, MYSQLI_ASSOC)) {
$arrResults = array($row['user_username']);
} // END WHILE
// Print them out, one per line
echo json_encode($arrResults);
推荐答案
Json必须采用以下格式:
Json have to be in this format:
[{label: 'label1', value: 'value1'},{label: 'label2', value: 'value2'},{label: 'label3', value: 'value3'}];
javascrip部分:
The javascrip part:
$( "#tags" ).autocomplete({
source: function( request, response ) {
var term = request.term;
$.ajax({
url: "username.php",
dataType: 'json',
async: true,
data: request,
timeout: 3000,
success: function(data,status,xhr){
response( data );
}
});
},
delay: 100,
minLength: 0
});
HTML
<input name="username" class="detailedViewTextBox suggest_hidden" id="tags" autocomplete='off' value="" type="text" size="18">
这篇关于如何使用jquery自动完成消息应用程序的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文