Keep in mind the way you used the jquery autocomplete. 1. First define a text box
<input type= "hidden" id= "Statid" value= "-1" >
<input type= "text" class= "Form-control graytips" id= " Statname "placeholder=" Please enter the site name/Pinyin First letter ">
2. Script
$ ("#statName"). AutoComplete ({source:function (request,response) {$.ajax ({
Type: "POST", url: "<%=path%>/jsp/stat.do?action=getstatlist", DataType: "JSON", Cache:false, Async:false, data: {"Statname": encodeURI ($ ("#statName"). Val ())}, Su Ccess:function (JSON) {var data = eval (JSON);//json Array response ($.ma
P (data,function (item) {var name = Item.name;
var id = item.id; return {label:item.code+ '--' + item.name,//drop-down box display value Valu
When e:item.name,//is selected, the value that is populated into the Drop-down box id:item.id//selected, and filled into the ID }
}));
}
}); delay:500,//delay 500ms facilitates input select:function (event, UI) {$ ("#statId"). Val (
Ui.item.id); }
});
3, Background action returns JSON format data,
Get param asynchronously Load site drop-down list String statname = Urldecoder.decode (Request.getparameter ("statname") = = null?
"": Request.getparameter ("Statname"). Trim (), "utf-8");
Jsonarray Jsonarray = new Jsonarray ();
Jsonobject jsonobject = new Jsonobject ();
Statservice service = new Statservice ();
List statlist = service.getstatlist (statname); if (statlist!= null) {for (int i = 0; i < statlist.size (); i++) {stationtable s = (Stationta
BLE) statlist.get (i);
Jsonobject.put ("id", S.getstatid ());
Jsonobject.put ("Name", S.getstatname ());
Jsonobject.put ("Code", S.getstatcode ());
Jsonarray.add (Jsonobject);
} PrintWriter pw = null;
StringBuffer sb = new StringBuffer ();
Sb.append (Jsonarray.tostring ());
try {response.setcontenttype ("TEXT/HTML;CHARSET=GBK");
PW = Response.getwriter ();
Pw.write (Sb.tostring ());
Pw.close ();
catch (IOException e) {e.printstacktrace (); }
4, the effect as shown:
————————————————————————————————————————————————— – Java Architect Project Combat, high concurrency cluster distributed, large data high availability video tutorials, total 760G
Download Address:
https://item.taobao.com/item.htm?id=555888526201
01. High-level architect 42 Phases
02.Java Advanced System Training Architecture Course 148 hours
03.Java Senior Internet Architect Course
04.Java Internet Architecture Netty, Nio, Mina, etc.-Video tutorials
05.Java Advanced Architecture Design 2016 finishing-video tutorials
06. Architect Foundation, advanced film
07.Java Architect Required Linux Operation series courses
08.Java Advanced System Training Architecture Course 116 hours
+
Hadoop series tutorials, Java design patterns and data structures, Spring Cloud Micro service, Springboot Primer
—————————————————————————————————————————————————–