gpt4 book ai didi

jquery - Mojolicious::Lite jQuery 自动完成问题

转载 作者:行者123 更新时间:2023-12-01 08:21:05 26 4
gpt4 key购买 nike

自动完成不起作用:是整个方法错误还是我只犯了一些错误?

#!/usr/local/bin/perl
use warnings; use 5.014; use utf8;
use Mojolicious::Lite;
use DBI;
my $dbh = DBI->connect( ... ) or die $DBI::errstr;
my $table = 'my_table';

get '/input' => sub {
my $self = shift;
$self->render( 'input' );
};

get '/search_db' => sub {
my $self = shift;
my $col = $self->param( 'col' );
my $sth = $dbh->prepare( "SELECT $col FROM $table" );
$sth->execute();
my $ref;
while ( my $row = $sth->fetchrow_arrayref() ) {
push @$ref, @$row;
}
$self->render( json => $ref );
};

app->start;

__DATA__
@@ input.html.ep
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="/js_local/development-bundle/jquery-1.6.2.js"></script>
<script src="/js_local/development-bundle/ui/jquery.ui.core.js"></script>
<script src="/js_local/development-bundle/ui/jquery.ui.widget.js"></script>
<script src="/js_local/development-bundle/ui/jquery.ui.position.js"></script>
<script src="/js_local/development-bundle/ui/jquery.ui.autocomplete.js"></script>
<script type="text/javascript">
$(function() {
$("#vorname").autocomplete({
source: '/search_db?col=vorname',
minLength: 2
});
});
</script>
</head>
<body>
<form>
<table>
<tr><td>Vorname:</td><td><input type="text" id="vorname"
name="vorname" autocomplete="off"/></td></tr>
<tr><td>Nachname:</td><td><input type="text" id="nachname"
name="nachname" autocomplete="on" /></td></tr>
</table><br />
<input type="submit" value="OK"/>
</form>
</body>
</html>

我认为我又向前迈进了一步:现在在第二个字符之后,我将所有名称显示为选择。

最佳答案

minLength 之后有一个额外的逗号:

$(function() { 
$("#vorname").autocomplete({
source: '/search_db?col=vorname',
minLength: 2,
});
});

首先尝试一下!

关于jquery - Mojolicious::Lite jQuery 自动完成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7358856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com