当输入 1 个字符时,它显示空白,标签在自动完成中丢失。我如何设置自动完成的标签。但是值(value)观来了。 这是带有输入类型文本的表单域。
<span>
<img src="images/author2.jpg" width="50" /> //in Database i have profilepic/userimage.jpg and the image shown in above is a static image.
<input class="searchStudent" type="text" autocomplete="off">
</span>
我输入了字母“A”,响应以数组形式出现。我想显示用户的照片和姓名,我该怎么做...?
这是我获取详细信息的脚本:
/*Search Student starts here*/
$(document).on("focus keyup", "input.searchStudent", function (event) {
$(this).autocomplete({
source: 'gdcontroller.php?action=search',
select: function (event, ui) {
event.preventDefault();
this.value = ui.item.label;
},
focus: function (event, ui) {
event.preventDefault();
this.value = ui.item.label;
}
});
});
/*Search Student ends here*/
这是我的 Controller ,我在这里搜索名为“A”的可用学生并获取他们的详细信息:
if($_GET['action']=="search" && $_GET['term']!='')
{
$keysearch = $_GET['term'];
$studentValue = trim($_GET['studentname']);
$studentsQuery =$conn->query('select s.student_pid,i.email,s.student_email,s.student_fname,s.student_lname,s.profile_pic from r_job_invitations i
LEFT JOIN tbl_students s ON i.email = s.student_email where i.id_job =54 and accounttype = 1 and inv_res = 1 and student_fname LIKE "'.$keysearch.'%" OR student_lname LIKE "'.$keysearch.'%" ')or die(mysqli_error());
$studentData = array();
while($student = $studentsQuery->fetch_assoc()){
$studentData[]= $student;
}
echo json_encode($studentData);
exit;
}
最佳答案
试试这个函数 mysql_real_escape_string()
关于php - jquery自动完成标签问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40928016/