2016-12-02 119 views
1

enter image description herejquery自动完成标签问题

当输入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”和响应即将到来的array.i要显示的照片和用户的名字,我怎么能做到这一点...?

这是从剧本我拿到的细节:

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

回答

2

你响应应该是JSON对象(数组),其中每个项目是具有id,labelvalue键的对象。

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

我不知道你要显示的他们,但你可以试试这个,例如:

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

你应该使用这些值发挥到显示你想要什么。

3

试试这个函数mysql_real_escape_string()