1. Returning requests from the background loading the ComboBox drop-down box data
HTML section
1 <name= "Matebelongz" ID= "Matebelongzid" style = "width:142px;height:20px;font-size:13px;border:1px Solid teal" > 2 </ Select >
JS section
1 $.ajax ({2url:rootpath+ '/jasframework/ycsy/querycamerabelongzid.do? ',3Success:function(Result) {5 varsehtml = "";6 for(vari = 0;i<result.length; i++) {7sehtml + = "<option>" +result[i].text+ "</option>";8 }9$ ("#mateBelongZID"). HTML (sehtml);Ten }, OneAsync:true, A dataType: "JSON" -});
Method Two, Easyui combobox control
$ ("#mateBelongZID"). ComboBox ({ url:rootpath+ '/jasframework/ycsy/ Querycamerabelongzid.do? ' , Valuefield:' id ', textField:' text ' }); // Adjust the width of the selection drop-down box Setcomboobjwidth ("Matebelongcid", "0.44", "ComboBox"); Setcomboobjwidth ("Matebelongzid", "0.44", "ComboBox");
The data format returned by both methods in the background is JSON-formatted data
Controller Layer/** * @return The search camera belongs to*/@RequestMapping ("/querycamerabelongzid") @ResponseBody public List Querycamerabelongzid (HttpServletRequest request) {//Push Login user information to the business classlist<?> list =Camerainfoservice.querycamerabelongzid (); returnlist; } Service Layer/** * Query the station the camera belongs to*/@Override public List Querycamerabelongzid () {//TODO auto-generated Method StubString sql = "from vectorinfo where Parenteventid = 202";//String sql = "SELECT * from ycsy_vectorinfo where Parenteventid = 202 vectorname is null and Workarea Name like '% Station ' and Parenteventid!=14 ';list<vectorinfo> list =workareainfodao.querycamerabelongzid (SQL); List List1=NewArrayList (); for(Vectorinfo camerainfo:list) {Map<String,String> map=NewHashmap<string,string>(); Map.put ("id", Camerainfo.getworkareaname ()); Map.put ("Text", Camerainfo.getworkareaname ()); List1.add (map); } returnList1; }
Note The data format returned by the note.
1 $.ajax ({2 Url:strurl,3Success:function(Result) {4 //alert (result);5 if(result==NULL){6Alert ("Sorry, the wells in the selected area have no layer information!") ");7}Else{8 varres =result;9 vararr = Res.split (",");Ten varsehtml = ""; One for(varValincharr) { Asehtml + = "<option>" +arr[val]+ "</option>"; - } -$ ("#cengwei"). HTML (sehtml); the } - - //$ ("Ol"). Append ("<li>appended item</li>"); - }, +Async:true, - dataType: "Text" +});
Front desk
1 < TD > 2 < ID= "Cengwei" style= "border:1px solid teal;" > 3 <!-- -4 </ Select >
Background
1 /**2 * Get all production-level information3 * 4 * @throwsIOException5 */6@RequestMapping ("/getallcengwei")7 @ResponseBody8 Public voidGetallcengwei (HttpServletRequest request, httpservletresponse response)throwsIOException {9String wellnames=request.getparameter ("Wellnames");TenString str= ""; One if(wellnames!=NULL&& "". Equals (Wellnames)) { Awellnames=Encodeutil.urldecode (wellnames); -String[] Wellname=wellnames.split (";"); - for(inti=0;i<wellname.length;i++){ thestr+= "'" +wellname[i]+ "',"; - } - } +String sql = "SELECT DISTINCT (CW) CW from Ycsy_newhorizon T where T.CW are not Null"; - if(str!=NULL&& "". Equals (str)) { +SQL + = "and T.jh in (" +str.substring (0, Str.length ()-1) + ")"; A } -List List =Workareainfoservice.getallcengwei (SQL); - String Cengwei = ""; - for(Iterator Iterator =list.iterator (); Iterator.hasnext ();) { -String obj =(String) Iterator.next (); - Cengwei + = obj + ","; in } - if(cengwei!=NULL&& "". Equals (Cengwei)) { toCengwei = cengwei.substring (0,cengwei.length ()-1); + } -Response.setcharacterencoding ("Utf-8"); the response.getwriter (). Write ("All tiers," + Cengwei); *}
Analysis: 1. Method One and note two The returned one is a JSON-formatted data is a string, both are used in Ajax, back to return the data format, the foreground data parsing format is not the same, note two (dataType: "Text")
Method One (dataType: "JSON"). Also a summary of the data format for parsing JSON: request with Ajax (DataType: "JSON" parsing, or result.) String, or eval (result).
2. Note that jquery dynamically adds elements.
Summary of remote loading data for ComboBox and summary of JSON data