jquery Auto完成标签问题(jquery Auto complete label issue)

输入1字符时,其显示空白,标签在自动完成时缺失。 我如何设置自动完成的标签。 但价值观即将到来。 这是带有输入类型文本的表单字段。

<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*/

这是我的控制员,我在这里搜索名字为“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; }

When Enter 1 Character , its showing Blank, Labels are Missing in Auto Completed. How can i Set the label for Autocomplete. But Values are coming. This is the form field with input type text.

<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>

I have entered letter "A" and the response is coming as a array.i want to show the photo and names of the user how can i do that...?

This is my from script to get the details:

/*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*/

This is my controller,here I am searching available students with name "A" and fetching their details:

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; }

最满意答案

您的回应应该是一个JSON对象(数组),其中每个项目都是具有id , label和value键的对象。

$studentData数组中的每个项目都应具有这些键以便自动完成显示数据。

我不确定你想要展示哪一个,但你可以尝试这个例子:

while($student = $studentsQuery->fetch_assoc()){ $student['id'] = $student['student_pid']; $student['label'] = $student['student_fname']; $student['value'] = $student['student_fname']; $studentData[]= $student; }

你应该玩这些值来显示你想要的。

Your response should be a JSON object (array) where each item is an object with id, label and value keys.

Each item in your $studentData array should have these keys in order for the autocomplete to show the data.

I'm not sure which of them you should like to display, but you can try this for example:

while($student = $studentsQuery->fetch_assoc()){ $student['id'] = $student['student_pid']; $student['label'] = $student['student_fname']; $student['value'] = $student['student_fname']; $studentData[]= $student; }

You should play with these values to display what you want.

更多推荐