使用Jquery的Ajax实例

$('#changId).change(function(){

             $.ajax({

                                   type: 'POST',

                                   data:"id="+$('#id).val(),

                                   url: 'whms.html?method=getType',

                                   success: function(json){

                                          var jsont = eval(json);                                           

                                             var row = "<option value='-1'>Please Select</option>";

                                             $('#selectId').append(row);

                                             $('# selectId').append(row);

                                             for(i=0;i<jsont.length;i++){

                                               json=jsont[i];

                                                  var id=json[0];

                                                  var name=json[1];

                                                  var row = "<option value="+id+">"+name+"</option>";

                                                  $('# selectId').append(row);

                                             }

                                   },

                                   error:function(data){

                                       alert("error!");

                                   }

                            })                 

                     });

 

//这里是控制器的部分

@RequestMapping(params = " method=getType")

public void getType (Model model, HttpServletRequest request, HttpServletResponse response) throws IOException {

       Long id = request.getParamater("id");

       ArrayList<Object> list = whmsManager.getType(id);

       JSONArray json = JSONArray.fromObject(list);

       PrintWriter out = null;

       out = response.getWriter();

       out.print(json.toString());

    }

 

 

//这里是业务逻辑的部分

public ArrayList<Object> getType (long id) {

       ArrayList<Object> al = new ArrayList<Object>();

       List<Whms> list = getMaterialType(Id);

       for (Type type: list) {

           ArrayList<String> innerList = new ArrayList<String>();

innerList.add(type.getId().toString());

           innerList.add(type.getName());

   innerList.add(type.getWhmsTypeName());

           al.add(innerList);

       }

       return al;

    }

 

:不能传入一个已经定义好的实体,因为JSONArray.fromObject,所以建议使用dwr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值