Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么JQuery/AJAX调用不起作用?_Php_Javascript_Jquery_Ajax - Fatal编程技术网

Php 为什么JQuery/AJAX调用不起作用?

Php 为什么JQuery/AJAX调用不起作用?,php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,最终尝试实现一个自动完成框。目前,我正在追随php学院的领导。当输入任何内容时,我只想在输入区域下方呼出“建议转到此处”。我必须整理文件home.php和country.phphome包含输入部分,而country.php只打印虚拟建议文本。现在当我在输入区输入时,什么也没发生。我使用的是jqueryv1.6.2(jquery-1.6.2.min.js) home.php是: <html> <head> <script type ="text/javascri

最终尝试实现一个自动完成框。目前,我正在追随php学院的领导。当输入任何内容时,我只想在输入区域下方呼出“建议转到此处”。我必须整理文件
home.php
country.php
home
包含输入部分,而
country.php
只打印虚拟建议文本。现在当我在输入区输入时,什么也没发生。我使用的是
jqueryv1.6.2
jquery-1.6.2.min.js

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>
从未见过。以前发布过。。。尝试使用$.post

$.post
不是

它会起作用的

如果您正在使用jquery

$.post("country.php", {countryPart:value}, function(data){
        $("#suggestions").html(data);
});
你写的

#.post
应该是

$.post

试试看:)

如果你真的在使用JQuery,你需要更改你的
post
调用:

$.post("country.php", {countryPart:value}, function(data){
    $("#suggestions").html(data);
});

在调用
post
之前,您使用的是
而不是
$

应该是
$。post

您可以像下面这样使用代码

$.ajax({
   type: "POST",
   url: "country.php",
   data: "name=value",
   success: function(data){
     $("#suggestions").html(data);
   }
 });
方法名称应为
$
不是
#


您可以使用“错误控制台”(monzilla firefox中的ctrl+shift+j)检查javascript/HTML执行中的错误

您确定它是“#.post”而不是“$.post”吗?输入错误
#.post
而不是“$.post”?如果不是这样,ajax调用是否出现在Firebug上?我错过了一个表单元素?这将给出不正确的HTML。不确定jQuery是否麻烦,但它可能会变得混乱…为什么您将答案作为注释而不是答案发布?假设在StackOverflow上发布时“#”/“$”是一个拼写错误,请检查控制台是否有任何错误。jQuery是否从正确的位置加载?(
/jquery.js
而不是
jquery.js
)。是
/country.php
还是
country.php
$.post("country.php", {countryPart:value}, function(data){
    $("#suggestions").html(data);
});
$.ajax({
   type: "POST",
   url: "country.php",
   data: "name=value",
   success: function(data){
     $("#suggestions").html(data);
   }
 });