0
我想通過GET或POST(如AJAX)值到我的PHP文件,該文件返回自動完成的json。我完全失去了我無法找到如何使用預取方法準備。這裏是我的代碼Prefetch準備BloodHound問題
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 [ '查詢']
<?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錯誤? – mplungjan
沒有任何控制檯和沒有錯誤,我測試了它的PHP文件效果很好,他只是在等待$ _GET ['query'] – Srithovic