jquery自动完成源不工作

问题描述:

我从jQuery autocomplete demo复制源代码并将相对URL替换为绝对URL,但是当我在localhost中测试页面时,自动填充小部件不起作用。谁能帮我?jquery自动完成源不工作

<html lang="en"> 

    <head> 
     <meta charset="utf-8" /> 
     <title>jQuery UI Autocomplete - Remote with caching</title> 
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> 
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
     <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> 
     <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" /> 
     <style> 
      .ui-autocomplete-loading { 
       background: white url('http://jqueryui.com/resources/demos/autocomplete/images/ui-anim_basic_16x16.gif') right center no-repeat; 
      } 
     </style> 
     <script> 
      $(function() { 
       $("#birds").autocomplete({ 
        source: "http://jqueryui.com/resources/demos/autocomplete/search.php", 
        minLength: 2 
       }); 
      }); 
     </script> 
    </head> 

    <body> 
     <div class="ui-widget"> 
      <label for="birds">Birds:</label> 
      <input id="birds" /> 
     </div> 
    </body> 

</html> 

您无法向其他主机发送请求。本地主机是不一样的jqueryui.com所以你被阻止same origin policy

+0

我替换源为“”:http://localhost/mirt_search.php“',这个页面将按照自动完成文档中所述的响应。但它仍然不起作用。有什么问题 – Zhao 2013-02-28 03:23:03

+0

@赵 - 控制台是否显示任何错误? Console里有显示什么错误吗? – 2013-02-28 03:27:54

+0

@Derek'http://localhost/mirt_search.php?term = 200'返回一个json数据,并且apache日志没有警告/错误。 – Zhao 2013-02-28 03:36:28