[英]Why does this JQuery/AJAX call not work?
Trying to implement an autocomplete box ultimately. 最终尝试实现自动完成框。 For now im following php academy's lead.
目前,我正在追随php学院的领导。 I just want to echo out "suggestions go here" underneath the input area when anything is entered.
输入任何内容后,我只想在输入区域下方回显“建议进入此处”。 I have to files.
我要归档。
home.php
and country.php
. home.php
和country.php
。 home
contains the input part and country.php
just prints the dummy suggestion text. home
包含输入部分, country.php
只是打印虚拟建议文本。 Right now when I type in the input area ..nothing happens. 现在,当我在输入区域中键入..什么都没有发生。 I am using
jquery v 1.6.2
( jquery-1.6.2.min.js
) 我正在使用
jquery v 1.6.2
( jquery-1.6.2.min.js
)
home.php
is: home.php
是:
<html>
<head>
<script type ="text/javascript" src ="jquery.js"></script>
<script type ="text/javascript">
function getSuggestions(value){
#.post("country.php", {countryPart:value}, function(data){
$("#suggestions").html(data);
});
}
</script>
</head>
<body>
<div id = "content_holder">
<input type = "text" name="country" value= "" id = "country" onkeyup="getSuggestions(this.value);" />
<div id ="suggestions"></div>
</div>
</body>
</html>
country.php
is country.php
是
<?php
echo "Suggestions Go Here";
?>
以前从未见过#.post ...尝试使用$ .post
$.post
not 不
#.post
it will work. 它会工作。
if you're working with jquery 如果您正在使用jQuery
$.post("country.php", {countryPart:value}, function(data){
$("#suggestions").html(data);
});
you wrote 你写了
#.post
should be 应该
$.post
try that :) 尝试:)
You can use like below code. 您可以使用以下代码。
$.ajax({
type: "POST",
url: "country.php",
data: "name=value",
success: function(data){
$("#suggestions").html(data);
}
});
If you're truly using JQuery, you need to change your post
call to this: 如果您真正使用的是JQuery,则需要将您的
post
调用更改为:
$.post("country.php", {countryPart:value}, function(data){
$("#suggestions").html(data);
});
You had #
instead of $
before the post
call. 你有
#
而不是$
的前post
通话。
应该是$.post
和#.post
The method name should be $
not #
方法名称应为
$
而不是#
you can use the "console of error"(ctrl + shift + j in monzilla firefox) for check error in javascript/HTML execution 您可以使用“错误控制台”(monzilla firefox中的ctrl + shift + j)检查javascript / HTML执行中的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.