Jquery ui JQuery ui自动完成不使用代码点火器

Jquery ui JQuery ui自动完成不使用代码点火器,jquery-ui,codeigniter,Jquery Ui,Codeigniter,我想做的很简单。我希望用户能够输入一个名称,并在插入代码点火器和jQueryUI时查找数据库并开始发布建议。。这就是我在stackoverflow上得到的一些帮助。。但它仍然根本不起作用 jqueryui命令 $("#update-text").autocomplete({source:"<?php echo site_url('userProfile/autocomplete');?>",dataType:"json", type:'POST'}); 下面的代码是为@Andrew

我想做的很简单。我希望用户能够输入一个名称,并在插入代码点火器和jQueryUI时查找数据库并开始发布建议。。这就是我在stackoverflow上得到的一些帮助。。但它仍然根本不起作用

jqueryui命令

$("#update-text").autocomplete({source:"<?php echo site_url('userProfile/autocomplete');?>",dataType:"json", type:'POST'});
下面的代码是为@Andrew添加的

<!-- styles -->
<link rel="stylesheet" type="text/css" href="<?php echo base_url().''?>public/styles/general.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url().''?>public/styles/homepage.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url().''?>public/styles/css-buttons.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url().''?>public/styles/colors.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url().''?>public/plugin/jqui/css/south-street/jquery-ui-1.8.11.custom.css"/>


<!-- scripts -->
<script type="text/javascript" src="<?php echo base_url().''?>public/scripts/removeTextClick.js"></script>
<script type="text/javascript" src="<?php echo base_url().''?>public/scripts/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<?php echo base_url().''?>public/plugin/jqui/js/jquery-ui-1.8.11.custom.min.js"></script>



<script type="text/javascript">

$(document).ready(function(){

    $("#abso").hide();
    $("#close").hide();

    $("#activity-feed").load("<?php echo site_url('userProfile/update_plan_feed');?>"); // if removed from userProfile then change here too
    $("#places-feed").load("<?php echo site_url('userProfile/suggested_places_feed');?>"); // if removed from userProfile then change here too
    $("#events-feed").load("<?php echo site_url('userProfile/suggested_events_feed');?>"); // if removed from userProfile then change here too




    $("#list-friends-feed-link").click(function(){ //start click

        $("#abso").load("<?php echo site_url('userProfile/list_freinds');?>");
        $("#abso").slideDown("600", function(){});
        $("#close").slideDown("600", function(){});

    }); //end click

    $("#list-pictures-feed-link").click(function(){ //start click

        $("#abso").load("<?php echo site_url('userProfile/pic_feed');?>");

        $("#abso").slideDown("600", function(){});
        $("#close").slideDown("600", function(){});
    }); //end click

    $("#list-groups-feed-link").click(function(){ //start click

        $("#abso").load("<?php echo site_url('userProfile/list_groups');?>");

        $("#abso").slideDown("600", function(){});
        $("#close").slideDown("600", function(){});
    }); //end click

    $("#notify").click(function(){ //start click

        $("#abso").load("<?php echo site_url('userProfile/list_notifications');?>");

        $("#abso").slideDown("600", function(){});
        $("#close").slideDown("600", function(){});
    }); //end click

    $("#close").click(function(){ //start click

        $("#abso").slideUp("600",function(){});
        $("#close").slideUp("600",function(){});
    }); //end click

    $("#broadcast-button").click(function(){

        $.post("<?php echo site_url('userProfile/send_broadcast'); ?>", $("#broadcast-form").serialize());

        });


    $("#update-text").autocomplete({source:"<?php echo site_url('userProfile/autocomplete');?>",dataType:"json", type:'POST'});


});


</script>


您要更改配置以正确设置自动完成:

$("#update-text").autocomplete("<?php echo site_url('userProfile/autocomplete');?>", {dataType:"json", type:'POST'});
编辑2:若要对您的请求使用POST,请尝试以下操作:

$("#update-text").autocomplete({ source: function( request, response ) {
                    $.post( "<?php echo site_url('userProfile/autocomplete');?", {
                        updateText: split(request.term).pop();
                    }, response );
                }});
$(“#更新文本”).autocomplete({来源:函数(请求,响应){

$.post(@Kay:如果你看到控制器对Firebug操作的响应,你看到正确的结果了吗?@Andrew No man,我没有得到任何解释:“$(“#更新文本”)。自动完成不是一个函数“@Kay:那样的话,你确定要在你的文档中的
脚本
标记中包含jQueryUI吗?@Andrew是的,我确定所有内容都包含在内。你有什么特别想看的吗?我编辑了上面的帖子,加入了一些你可能想看的代码。1)我不确定嵌套函数在类中是否会像这样工作2)我100%确定你不能在类方法中使用
array\u filter
这样,@Femi抱歉,我有点困惑。我不完全理解。啊,是的:你需要将你在CodeIgniter中使用的请求参数改为term,而不是updateText。还有(不幸的是)jQueryUI的内置远程数据源似乎只使用GET,而不使用POST(请参阅中的详细讨论):因此,您需要实现您自己的自定义远程数据源,或者确保您的CodeIgniter应用程序接受GET请求。我添加了一个可能的自定义源,使用POST并调用CI:让我知道这是否有效。@Femi OK,所以我试过了,Firebug被卡住了,我无法单击该页面上的任何内容,我发现autocomplete不是一个函数错误。我如果认为括号有问题,我猜jQueryUI加载不正确。
$("#update-text").autocomplete("<?php echo site_url('userProfile/autocomplete');?>", {dataType:"json", type:'POST'});
  function autocomplete(){
    // this takes the text field and whatever the user writes it autocompletes it.
    //Every single place and event in the database should be displayed in this view in this format
    $req = $this->input->post('updateText');

  $arrResults = array('orange', 'apple', 'bannana');

  function mycallback ($var) {
    global $req;

    if (preg_match('/^'.$req.'/', $var)) {
      return $var;
    }
  }

  $array = array_filter($arrResults, 'mycallback');
  // filter the array containing search word using call back function

  $array1 = array();

  // filter null array
  foreach ($array as $arr => $val) {
    if(!empty($val)) {
      $array1[] = $val;
    }
  }

  //echo out the json encoded array
  echo json_encode($array1);
}
$("#update-text").autocomplete({ source: function( request, response ) {
                    $.post( "<?php echo site_url('userProfile/autocomplete');?", {
                        updateText: split(request.term).pop();
                    }, response );
                }});