mybatis ajax json,STRUS2+MYBATIS+SPRING ajax+json 返回list 给select 实现级联

很早就想研究一下ajax 通过json 方式走action 返回list 给前台 显示,今天终于做出来了,把代码贴出来分享给大家ajax json 方式需要jar包,一会从附件分享给大家。

首先我用的开发框架式ssi2,接下来我把代码帖给大家。

(1)前台页面jhxdxukezheng.jsp

function plannochange(){

var planno=$("#planno").val();

$.ajax({

type : 'post',

url : 'SampleAction_selectProducttypeByPlanno',

dataType:'json',

data : {

planno : planno,

},

success : function(data) {

// alert(data);

$("#producttype").empty();

//   $("#producttype").append("请选择");

$.each(data, function (i, item) {

//             alert(item.name + ","  +item.value);

$("#producttype").append(""+item.value+"");

});

},

error:function(){

alert("错误");

}

});

};

计划编号:

listValue="planno" id="planno" οnchange="plannochange()">

产品类型:

(2)action 类

public String selectProducttypeByPlanno() {

response.setContentType("text/html;charset=UTF-8");

String planno = request.getParameter("planno");

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

}

注:1.这里数据传输方式为:json方式{"1":"aa","2":"bb"}

2.  $("#producttype").empty()代表下拉列表清空  alert(item.name + ","  +item.value);

$("#producttype").append(""+item.value+"");代表下来列表追加

3.JSONArray jsonarry = JSONArray.fromObject(producttypelist)代表把list集合转化成jsona    rry格式,再 用PrintWriter流输出参数jsonarry.toString()返给前台页面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值