【发布时间】:2011-08-19 19:39:24
【问题描述】:
我真的希望避免发布新问题,但我找不到一个包含调用页面和“搜索”页面的 jQuery Autocomplete Remote 功能的有效示例。 jQueryUI“Demos & Documentation”部分不包含“search.php”的源代码
我尝试了几十种组合,但这是我开始的:
<style>
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script>
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).attr( "scrollTop", 0 );
}
$( "#birds" ).autocomplete({
source: "search.php",
minLength: 1,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
});
</script>
<div class="demo">
<div class="ui-widget">
<label for="birds">Birds: </label>
<input id="birds" />
</div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>
</div>
和search.php:
$conn = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE", $conn);
$q = strtolower($_GET["birds"]);
$query = mysql_query("select FIELD from TABLE where FIELD like '%$q%'");
while ($row = mysql_fetch_array($query)) {
echo json_encode($row);
}
有没有人可以共享代码 sn-ps 来显示这个等式的两边?非常感谢您提供的任何帮助。
【问题讨论】:
-
你喜欢在 SQL 注入后清理吗?
-
alex,关于使用自动完成和防止 SQL 注入的方法有什么建议吗?
标签: php jquery mysql autocomplete