Process:
1. Click Load BTN to initiate the asynchronous request post
2. Background processing request return data
3. Front-end acquisition of data successfully, data processing
Front:
HTML: First to import the JQ package, otherwise how to use Ajax it.
<script type= "Text/javascript" src= "Js/jquery.js" ></script>
<select name= "Warid" id= "Warid" style= "height:100%;width:107px" ><option value= "" > All warehouses </option> </select>
<script type= "Text/javascript" >$ (document). The Ready (function () { ///is implemented here: Loads the warehouse list $ (". Add") When you click the Add button for class. Click (function () {$.post ("xxxx.do", function (data) { ////action to be loaded asynchronously, and a successful callback var objs = data.warehouses; The attribute in the corresponding action var selobj = $ ("#wareId"); Selobj.empty (); for (var i in Objs) {var obj = objs[i];addoption (selobj,obj.id,obj.warehousename);//Append an option to select ( Drop-down) }}, "JSON"); return type}); }); function AddOption (selobj,value,text) {var optionstring = "<option value=\" "+ Value +" \ ">" + text + "</option > "; selobj.append (optionstring); Append an option to the Select (drop-down item) }</script>
Backstage structs:
Using annotation implementations,
Note that the Declaration class should be annotated: @ParentPackage ("Json-default")
Method declaration Annotations: @Action (value = "xxxx", results = @Result (name = "Success", type= "JSON"))
Need to jump page to change type = "JSON" to location = "/mobile/auction_detailed.jsp" to jump to the page
@ParentPackage ("Json-default") public class Warhouseaction extends Actionsupport {@Autowiredprivate Warehouseservice Warehouseservice;private list<warehouse> warehouses;/** * Background ajax * @return * need to jump page to change type = "JSON" to location = "/mobile/auction_detailed.jsp" the page to jump */@Action (value = "Addgood_before", results = @Result (name = "Success", type= "json ")) public String Addgoodbefore () {warehouses = Warehouseservice.findallenablewarehouses (); This is the return to the page "Success";} Public Warehouseservice Getwarehouseservice () {return warehouseservice;} public void Setwarehouseservice (Warehouseservice warehouseservice) {this.warehouseservice = Warehouseservice;} Public list<warehouse> getwarehouses () {return warehouses;} public void setwarehouses (list<warehouse> warehouses) {this.warehouses = warehouses;}}