-1

自动完成功能附加到这个 id="search" 的输入字段。当我输入文本时,什么都没有显示,这与我在另一个文件的另一个文本字段上使用 Jquery UI 日历之前出现了几次的搜索结果相反。

CHROME 中的开发者控制台和 Firefox 中的 Firebug 没有显示错误,而是显示“XHR 完成加载”。我不知道出了什么问题!请帮忙。

默认的.php

<script src="jquery-1.9.1.js"></script>
<script src="jquery-ui-1.10.3.custom.min.js"></script>
<script src="myfunctions.js"></script>
<link rel="stylesheet" type="text/css" href="jquery-ui-1.10.3.custom.min.css"/>
<link rel="stylesheet" type="text/css" href="main.css"/>

    <div id="search_container"><input type="text" onkeyup="showHint(this.value)"  id="search" placeholder="Search here"/></div>

myfunctions.js

function showHint(strvalue)
{
   $("#search").autocomplete({
       minLength:2,
     source: "getHint.php?search="+strvalue,
     select:function(ui)
              {
                  log(ui.item?
                  window.location.replace(ui.item.link):
                  "Not Found");
              }
    }
         ).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
         .data("item.autocomplete", item)
         .append("<a>" + item.label + "</a>")
         .appendTo(ul);
 };
}

获取提示.php

<?php
require_once 'myfunctions.php';
$search=sanitizeString($_GET['search']);
$query="Select * from students where firstname like '%$search%' or lastname like '%$search% order by firstname'";
$result=  queryMysql($query);
$k=0;
while($row=  mysql_fetch_array($result))
{
    $email=$row['email'];
    $name=nameOf($email);
    $studentid=studentidOf($email);
    $as[]['label']="<a style='text-decoration:none' href='student_profile.php?studentid=$studentid'><div class='search_elements'><span class='search_elements_span'>$name</span></div></a>";
    $as[$k++]['value']=$name;

}

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

echo json_encode($as);

main.css

#search_container
{
position: relative;
top:1px;
left:750px;
width:250px;

}

#search
{
font-family: cursive;
font-size: 14px;
color: #999999;
width:250px;
position:relative;
background: white;
z-index: 11;
top: 1px;
}

#search:focus
{

font-family: cursive;
font-size: 14px;
width: 250px;
color: black;
}

在浏览器中检查代码时,输​​入文本区域在我搜索项目后显示如下:

<input id="searchstr" class="ui-autocomplete-input" type="text" placeholder="Search here" name="searchstr" autocomplete="off"></input>

为什么自动完成属性设置为“关闭”?

4

1 回答 1

0

getHint.php 所需的文件“myfunctions.php”正在打印数据。如果 getHint.php 文件必须以 JSON 的形式对数组或数据进行编码,则不应打印或“回显”任何内容。

从“myfunctions.php”中删除打印数据效果非常好。可以通过 Mozilla Firefox 中的 FIREBUG 应用程序检查 JSON 编码的数据。

于 2013-08-28T18:32:56.923 回答