我在PHP中使用Jquery AutoComplete 这是我的主页代码:
$( "#umr" ).autocomplete({
source:'getpatient.php',
select: function( event, ui ) {
alert(ui.item.userId);
$( "#umr" ).val( ui.item.userId );
$( "#email1" ).val( ui.item.email );
$( "#fname1" ).val( ui.item.fname );
$( "#lname1" ).val( ui.item.lname );
$( "#mobile1" ).val( ui.item.mobile );
$( "#insurance1" ).val( ui.item.insurance );
return false;
}
});
这是我的后端代码:
while($rows=mysqli_fetch_array($query)){
$data[] = array(
'userId' => $rows['user_id'],
'email' => $rows['email'],
'fname' => $rows['fname'],
'lname' => $rows['lname'],
'mobile' => $rows['mobile'],
'insurance' => $rows['insurance']
);
}
echo json_encode($data);
自动完成文本框显示如下结果:
但是我在自动填充中检查警报时获得了结果
答案 0 :(得分:0)
作为来源,我添加ajax request to fetch
getpatient.php
$( "#umr" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "getpatient.php",
dataType: "jsonp",
data: {
q: request.term
},
success: function( data ) {
response( data );
}
});
},
select: function( event, ui ) {
alert(ui.item.userId);
$( "#umr" ).val( ui.item.userId );
$( "#email1" ).val( ui.item.email );
$( "#fname1" ).val( ui.item.fname );
$( "#lname1" ).val( ui.item.lname );
$( "#mobile1" ).val( ui.item.mobile );
$( "#insurance1" ).val( ui.item.insurance );
return false;
}
});