Я новичок в jQuery. Я пытаюсь JQuery автозаполнения удаленного источника данных Вот мой код:jquery autocomplete удаленный источник данных
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Quanta Plus">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
</head>
<body>
<meta charset="utf-8">
<style>
.ui-autocomplete-loading {
background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;
}
</style>
<script>
$(function() {
var cache = {},
lastXhr;
$("#birds").autocomplete({
minLength: 2,
source: function(request, response) {
var term = request.term;
if (term in cache) {
response(cache[ term ]);
return;
}
lastXhr = $.getJSON("search.php", request, function(data, status, xhr) {
cache[ term ] = data;
if (xhr === lastXhr) {
response(data);
}
});
}
});
});
</script>
<div class="demo">
<div class="ui-widget">
<label for="birds">Birds: </label>
<input id="birds" value="" />
</div>
</div><!-- End demo -->
</body>
</html>
FILE: search.php
<?php
require_once("includes/connection.php");
$q = strtolower($_GET["birds"]);
echo $q;
$return = array();
$query = "SELECT title
FROM `project`
WHERE `title` LIKE CONVERT(_utf8 '%$q%'
USING latin1)";
$resultset=mysql_query($query,$connection);
$json = '[';
$first = true;
while ($row = mysql_fetch_assoc($resultset)) {
if (!$first) {
$json .= ',';
} else {
$first = false;
}
$json .= '{"value":"'.$row['title'].'"}';
}
$json .= ']';
echo $json;
?>
получает следующее сообщение об ошибке:
Notice:
Undefined
index: birds in /var/www/html/workbench/sudeepc/project/search.php
on line 4
[
{"value":"chandrayaan"},
{"value":"Project Management System"},
{"value":"shoping cart"},
{"value":"hospital management system"}
]
ошибка при обнаружении ошибки при поиске в этом текстовом поле и нет предложения для поиска.
Как решить эту проблему?
Видимо '$ _GET [" birds "]' не существует. Что произойдет, если вы замените это на '$ _POST [" birds "]'? – Blazemonger
$ q = strtolower ($ _ POST ["birds"]); это приводит к той же ошибке –
Поскольку он вызывает '$ .getJSON()', он должен загружать данные в '$ _GET ['birds']'. PHP не будет вызывать ошибку, основанную на отсутствии значения GET в любом случае - это просто пустое значение. –