【问题标题】:jquery Auto complete label issuejquery自动完成标签问题
【发布时间】:2017-04-17 02:48:09
【问题描述】:

当输入 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;
}

【问题讨论】:

    标签: php jquery mysql ajax autocomplete


    【解决方案1】:

    试试这个函数 mysql_real_escape_string()

    【讨论】:

      【解决方案2】:

      您的响应应该是一个 JSON 对象(数组),其中每个项目都是一个带有 idlabelvalue 键的对象。

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

      我不确定你应该显示哪一个,但你可以试试这个,例如:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-08
        • 2010-12-04
        • 2011-08-08
        • 2013-01-22
        • 2016-05-31
        • 2011-10-08
        相关资源
        最近更新 更多