Ldap autocomplete with Jquery
Here is my script
$(document).ready(function(){
$("#responsable").autocomplete('/personquery');
minLength: "3";
});
And corresponding controller method:
@RequestMapping(value ="/personquery",method= RequestMethod.GET)
@ResponseBody public void getUids(HttpServletResponse response){
String personList = null;
List <Person> ldapUsers = ldap.getUids();
for (int i=0;i<ldapUsers.size();i++) {
personList+=ldapUsers.get(i).getUid()+"\n";
System.out.println(ldapUsers.get(i).getUid()+"\n");
}
}
Anyhow, the script doesn't seem to call the controller method. The method can contain some faults too, since I've not been able to test it开发者_如何学运维. Any help?
It looks like you are using MVC.
We've done something similar in one of our projects. This seems to work:
The script initialises the autocomplete text box. It uses a service call to return a list of user names
$("#textBoxId").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%: Url.Action("GetADUsers", "ADUser") %>',
dataType: "json",
data: request,
success: function (data) {
response(data);
}
});
}
});
Then our action method on the controller looks something like this:
public ActionResult GetADUsers(string term)
{
List<string> users = SearchForUsers(term); //this is just a method that queries AD
return new JsonResult() { Data = users.ToArray(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
精彩评论