Strus2+mybatis+spring Ajax+json returns list to cascade for select

Source: Internet
Author: User



Very early to study Ajax through the JSON way to go back to the list to the foreground display, today finally made out, put the code to share to everyone


    1. The Ajax JSON method requires a jar package, which is shared from the attachment to everyone.

    2. First I used the development framework of SSI2, and then I put the code to everyone.

      (1) front page jhxdxukezheng.jsp

<script type = "text / javascript">
function plannochange () {
var planno = $ ("# planno"). val ();
$ .ajax ({
type: ‘post’,
url: ‘SampleAction_selectProducttypeByPlanno’,
dataType: ‘json’,
data: {
planno: planno,
Hell
},
success: function (data) {
// alert (data);
$ ("# producttype"). empty ();
// $ ("# producttype"). append ("<option> Please choose </ option>");
$ .each (data, function (i, item) {
// alert (item.name + "," + item.value);
$ ("# producttype"). append ("<option value =‘ "+ item.name +" ‘>" + item.value + "</ option>");
Ranch
});
Hell
},
error: function () {
alert ("Error");
}

});

};

</ script>

<b> Plan ID: </ b>
<s: select list = "# request.plannolist" listKey = "planno"
listValue = "planno" id = "planno" onchange = "plannochange ()"> </ s: select>
<b> Product type: </ b>
<s: select list = "jsonarry" listKey = "name" listValue = "value" headerKey = "1" headerValue = "Please select" id = "producttype"> </ s: select>
(2) action class
    public String selectProducttypeByPlanno () {
response.setContentType ("text / html; charset = UTF-8");
String planno = request.getParameter ("planno");
List <Producttype> producttypelist = sampleService
.selectProducttypeByPlanno (planno);
JSONArray jsonarry = JSONArray.fromObject (producttypelist);

try {
PrintWriter out = response.getWriter ();
System.out.println (jsonarry.toString ());
out.print (jsonarry.toString ());
out.flush ();
out.close ();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
return null;

}
Note: 1. The data transmission method here is: json method {"1": "aa", "2": "bb"}
    2. $ ("# producttype"). Empty () means empty the drop-down list alert (item.name + "," + item.value);
$ ("# producttype"). append ("<option value =‘ "+ item.name +" ‘>" + item.value + "</ option>");
    3.JSONArray jsonarry = JSONArray.fromObject (producttypelist) represents converting the list collection into jsona rry format, and then using PrintWriter stream output parameter jsonarry.toString () to return to the front page 








This article is from the "Big Talk Program" blog, please be sure to keep this source http://houqida.blog.51cto.com/8877896/1580003



Strus2+mybatis+spring Ajax+json returns list to cascade for select


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.