预取 准备寻血猎犬问题



我想将GET或POST(如AJAX(值传递给我的php文件,该文件返回json以进行自动完成。我完全迷路了,我找不到如何使用预取方法准备。这是我的代码

Html/JS

$(document).ready(function() {
  var communautes = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('communaute'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: '/plugins/autocomplete/getCommu.php'
  });
  var peoples = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('people'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: {
      url: '/plugins/autocomplete/getPeople.php?query=%QUERY',
      cache: false
    }
  });
  $('.multiple-datasets .typeahead').typeahead({
    highlight: true
  }, {
    name: 'Communautes',
    display: 'communaute',
    source: communautes,
    templates: {
      header: '<h6>Communautés</h6>'
    }
  }, {
    name: 'People',
    display: 'people',
    source: peoples,
    templates: {
      header: '<h6>Personnes</h6>'
    }
  });
});
<div class="row">
  <div class="col-md-4 col-md-offset-3">
    <form action="recherche.php" class="search-form">
      <div class="form-group has-feedback multiple-datasets">
        <input type="text" class="form-control typeahead" name="search" id="search" placeholder="Rechercher" autocomplete="off">
        <span class="glyphicon glyphicon-search form-control-feedback"></span>
      </div>
    </form>
  </div>
</div>
</div>

这是我的 php 文件,我试图在其中获取 $_GET['query']

<?php
    require_once $_SERVER['DOCUMENT_ROOT'].'/config.php';
    require_once $_SERVER['DOCUMENT_ROOT'].'/plugins/LDAP/setLDAP.php';
    $ldap=getLDAP();
    $dn = $GLOBALS['userGroup'].",".$GLOBALS['domain'];
    $filter="(|(".$GLOBALS['nom']."=".$_GET['query']."*)(".$GLOBALS['prenom']."=".$_GET['query']."*))";
    $justthese = array($GLOBALS['nom'],$GLOBALS['prenom']);
    $sr=ldap_search($ldap, $dn, $filter, $justthese);
    $info = ldap_get_entries($ldap, $sr);
  if($info['count']!=0){
    for ($i=0; $i < $info['count'] ; $i++) {
      $tab[]['people']=$info[$i][$GLOBALS['prenom']][0]." ".$info[$i][$GLOBALS['nom']][0];
    }
    echo json_encode($tab);
  }
  else echo "Aucune personne trouvée";
?>
如果

有人需要解决这个问题,我会找到一种方法来做到这一点,但忘记预取

这是我的做法(使用遥控器(:

    var peoples = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('people'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
      remote: {
      wildcard: '%QUERY',
      url: '/plugins/autocomplete/getPeople.php?query=%QUERY'
      }
    });

相关内容

  • 没有找到相关文章

最新更新