jQuery UI自动完成不起作用

问题描述:

我试图使用jQuery UI自动完成但它不显示任何列表或任何东西。据我所知,没有必要用jQuery UI声明ullijQuery UI自动完成不起作用

<html> 
    <head> 
     <link href="./jquery-ui.css" rel="stylesheet"> 

     <script src="./jquery-1.11.1.js"></script> 
     <script src="./jquery-ui.js"></script> 
    </head> 

    <body> 
     <input id="pu_location" size="38" type="text" />        
     <input type="hidden" id="pu_locationID" /> 

     <script> 
      Script is below. 
     </script> 
    </body> 
</html> 

脚本:

<script> 

$(document).ready(function() { 

     $("#pu_location").autocomplete({ 

      source: function(request, response) { 

      $.getJSON("/test.php", { country_code: "USA",term:$('#pu_location').val()}, 
         function(data) { 
         alert(data[0].id); 
         var array =[]; 
         for(key in data){ 
          if (data[key].label!=''){ 
           array.push(data[key].label); 
           } 
          } 
          alert(array); 
          response(array); 
         }); 
      }, 
      delay: 100, 
      minLength: 3       
      }); 
}); 
</script> 

顺便说一句,在data是完美的。 alert表明一切都很好。

被修改: 它现在可以与Chrome一起使用,但不能与Firefox一起使用!

+0

你可以格式化代码位,这将是更多pleasent眼睛:) – Beri 2014-10-03 06:33:58

+0

我试过了。我正在使用一个简单的文本编辑器。 – Arnold 2014-10-03 06:39:21

+0

@Beri没有'$(function(){'和'function(request,response){'作为'$(“#pu_location”)之外的函数。'autocomplete {{代码看起来好多了,你知道.. 。 – Regent 2014-10-03 06:47:28

第一个线索: 删除:

$(function() { 

你是想在这里创造selfexecuting JS的功能,但它是没有必要的,因为你已经在准备功能annonymus功能。

然后把一个日志只是线

$("#pu_location").autocomplete({ 

之前只是要确定正在执行该代码。第二条线索:你在回应数据时感受数据,然后创建并填充数组,最后传递给响应数据,那么处理的意义是什么?

+0

它被执行并且警报显示正确的数据。我刚刚删除了那个,并且仍然不会显示检索到的内容 – Arnold 2014-10-03 06:42:06

+0

也尝试过使用数据变量和创建的字符串数组,但没有运气 – Arnold 2014-10-03 06:43:58

+0

Array理由:我认为响应无法处理对象,所以我用字符串做了一个数组,没有工作 – Arnold 2014-10-03 06:46:54