Call the AutoComplete method by using the ID to take the input tag object
<Script> varsources= [ "ActionScript", "AppleScript", "ASP", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; $(function() { $( "#tags"). AutoComplete ({source:sources}); });</Script><Body> <Divclass= "Ui-widget"> <H2>Inquire:<inputID= "tags"></H2> </Div></Body>
{Source:sources} wraps multiple sources array of string types into JSON.
Ajax server-Side completion:
Java code for server-side Web pages, and Java code only.
String query = request.getparameter ("term");//get the parameters to matchstring[] sources = {"ActionScript", "AppleScript", "Asp", "BASIC", C, "C + +", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme"}; StringBuilder Builder=NewStringBuilder ("["); for(inti=0;i<sources.length;i++) {//iterates through the target array, returning the results that match the criteria if(NULL!=query) { if(Sources[i].indexof (query) >= 0) {//string that indicates if Query,sources[i] was entered contains a string queryBuilder.append ("{\" label\ ": \" "+sources[i]+" \ "},");//JSON data stitched into {"label": Sources[i]} } }Else{//If you do not enter query, return all Sources[i] as a JSON array.Builder.append ("{\" label\ ": \" "+sources[i]+" \ "},"); }} String result= Builder.tostring ();//converted to a string. if(Result.endswith (",")) {//because the concatenation result is converted into a string, the array will be more ","result = Result.substring (0,result.length ()-1);//The last comma needs to be truncated.} result+="]";//stitching "]"out.print (Result);
View Code
Script
$(function() { $( "#tags"). AutoComplete ({Source:function(request,response) {//The request.term estimate is the string after the input content is submitted. " Term= ' string ', in fact, is equivalent to passing in a //{"term": JSON data for "string"}. Specifically described in the jQuery1.11.10 Help document, search get second is.$.get ("server/demo4_server.jsp", "term=" +request.term,function(data) {//URL (destination address), data (incoming), callback (callback function) varresult =$.parsejson (data); Response (result);//output return result }); } }); });
View Code
Parsejson (String strjson) function:
[Easyui] AutoComplete simple autocomplete and Ajax done from the server side