我试图从ajax帖子中将参数传递给perl,但perl却看不到它......
HTML:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").keyup(function(){
txt=$("input").val();
$.post("search1.pl",{suggest:txt},function(result){
$("span").html(result);
});
});
});
</script>
</head>
<body>
First name:
<input type="text" />
<p>Suggestions: <span></span></p>
</body>
</html>
perl的:
#!/usr/bin/perl
use CGI;
my $q = CGI->new;
my $txt = $q->param('txt');
print "Content-type: text/html\n\n";
print "txt=$txt<br>";
print "HAHA1<br>";
print "HAHA2<br>";
输出:
建议:txt =
HAHA1
HAHA2
我希望看到“txt =”包含我在输入框中输入的内容
任何线索??
答案 0 :(得分:3)
您已调用参数suggest
$.post("search1.pl",{suggest:txt}
但您正在尝试阅读名为txt
的内容。
更改为:
my $txt = $q->param('suggest');