par
kevin254kl » 23 nov. 2016, 17:25
Bon finalement j'ai bricolé quelque chose, mais je trouve cela compliqué je fais mon json a partir d'un string mais doit y avoir un moyen plus simple
Code : Tout sélectionner
<link rel="stylesheet" href="css/jquery-autocomplete.css" >
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<link rel="stylesheet" href="css/jquery-autocomplete.css" >
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<input id="tags" >
<script>
$('#tags').autocomplete({
source: function (request, response) {
$.getJSON("fichier.php?term=" + request.term, function (data) {
response($.map(data.info, function (value) {
return value.nom;
}));
});
},
minLength: 2,
delay: 100
});
</script>
Code : Tout sélectionner
<?php
if(isset($_GET['term'])) {
include_once('Connexion/ldap_connexion.php');
$q = utf8_decode($_GET['term']);
$ldapConn = ldap_connect($ldapServer ) or $error_ldap_connect = true;
$query = "(|(sn=$q*)(givenname=$q*)(mail=$q*)(login=$q*))";
ldap_set_option($ldapConn,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapConn,LDAP_OPT_REFERRALS,0);
$ldapBind = ldap_bind($ldapConn,$rdn,$mdp);
$ldapResult = ldap_search($ldapConn,$baseDN,$query);
$info = ldap_get_entries($ldapConn,$ldapResult);
$Json = '{
"info" : [';
for ($i=0; $i < $info ["count"] - 1; $i++)
{
$Json .= '{"prenom":"'.$info[$i]["givenname"][0] ;
$Json .= '","nom":"'.$info[$i]["sn"][0] ;
$Json .= '","mail":"'.$info[$i]["mail"][0] ;
$Json .= '","login":"'.$info[$i]["samaccountname"][0].'"},' ;
// $Json[$i]['prenom'] = $info[$i]["givenname"][0] ;
// $Json[$i]['nom'] = $info[$i]["sn"][0];
// $Json[$i]['mail'] = $info[$i]["mail"][0];
// $Json[$i]['login'] = $info[$i]["samaccountname"][0];
}
$Json .= '{"prenom":"'.$info[$info ["count"] - 1]["givenname"][0] ;
$Json .= '","nom":"'.$info[$info ["count"] -1]["sn"][0] ;
$Json .= '","mail":"'.$info[$info ["count"] -1]["mail"][0] ;
$Json .= '","login":"'.$info[$info["count"] -1]["samaccountname"][0].'"}]}' ;
ldap_unbind($ldapConn);
echo $Json;
header("Content-Type: application/json");
}
?>
Bon finalement j'ai bricolé quelque chose, mais je trouve cela compliqué je fais mon json a partir d'un string mais doit y avoir un moyen plus simple
[code]<link rel="stylesheet" href="css/jquery-autocomplete.css" >
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<link rel="stylesheet" href="css/jquery-autocomplete.css" >
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<input id="tags" >
<script>
$('#tags').autocomplete({
source: function (request, response) {
$.getJSON("fichier.php?term=" + request.term, function (data) {
response($.map(data.info, function (value) {
return value.nom;
}));
});
},
minLength: 2,
delay: 100
});
</script>[/code]
[code]<?php
if(isset($_GET['term'])) {
include_once('Connexion/ldap_connexion.php');
$q = utf8_decode($_GET['term']);
$ldapConn = ldap_connect($ldapServer ) or $error_ldap_connect = true;
$query = "(|(sn=$q*)(givenname=$q*)(mail=$q*)(login=$q*))";
ldap_set_option($ldapConn,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapConn,LDAP_OPT_REFERRALS,0);
$ldapBind = ldap_bind($ldapConn,$rdn,$mdp);
$ldapResult = ldap_search($ldapConn,$baseDN,$query);
$info = ldap_get_entries($ldapConn,$ldapResult);
$Json = '{
"info" : [';
for ($i=0; $i < $info ["count"] - 1; $i++)
{
$Json .= '{"prenom":"'.$info[$i]["givenname"][0] ;
$Json .= '","nom":"'.$info[$i]["sn"][0] ;
$Json .= '","mail":"'.$info[$i]["mail"][0] ;
$Json .= '","login":"'.$info[$i]["samaccountname"][0].'"},' ;
// $Json[$i]['prenom'] = $info[$i]["givenname"][0] ;
// $Json[$i]['nom'] = $info[$i]["sn"][0];
// $Json[$i]['mail'] = $info[$i]["mail"][0];
// $Json[$i]['login'] = $info[$i]["samaccountname"][0];
}
$Json .= '{"prenom":"'.$info[$info ["count"] - 1]["givenname"][0] ;
$Json .= '","nom":"'.$info[$info ["count"] -1]["sn"][0] ;
$Json .= '","mail":"'.$info[$info ["count"] -1]["mail"][0] ;
$Json .= '","login":"'.$info[$info["count"] -1]["samaccountname"][0].'"}]}' ;
ldap_unbind($ldapConn);
echo $Json;
header("Content-Type: application/json");
}
?>[/code]