structs2 annotation +jsp+ajax Implementation post asynchronous load Select

Source: Internet
Author: User

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;}}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.