【问题标题】:Prefetch Prepare BloodHound issue预取准备 BloodHound 问题
【发布时间】:2017-06-13 09:56:48
【问题描述】:

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

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>

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

<?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";
?>

【问题讨论】:

  • 控制台有什么东西吗?任何 PHP 错误?
  • 控制台什么也没有,也没有错误,我测试了PHP文件,效果很好,他只是在等待$_GET['query']

标签: php jquery ajax typeahead.js bloodhound


【解决方案1】:

如果有人需要解决这个问题,我会找到一种方法来解决这个问题,但忘记了 prefetch

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

    var peoples = new Bloodhound({

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

    });

【讨论】:

    猜你喜欢
    • 2012-10-12
    • 2013-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多