2016-12-02 120 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()