对于Jquery我都学习了快接近两年了,但是没有完全通过jquery做过一个完整的项目.大部分的项目的是自己擅长用什么预言就拼凑什么. 下面是对于jquery的post的提交.一直以来都是用的这一种方法.但是依旧不是很熟练,今天就给发表这里吧,有时间就来回顾一下.
checkBox的写法:
$.post("/communityweb/AjaxAllServlet", {change:"getFushuhangye",bigClassId:obj}, function(data){ $("#tdfushu").empty(); $.each(data,function(key,value){ var input=$("<input type='checkbox' name='subIndustryId' id='subIndustryId'/>").val(key); $("#tdfushu").append(input).append(value); }); },"json");
if("getFushuhangye".equals(change)){//异步查询附属行业 String bigClassId=request.getParameter("bigClassId"); Shop shop=new Shop(); JSONObject json=new JSONObject(); Resultobj ro=shop.getSubIndustry(bigClassId); try { for(int i=1;i<ro.getRows();i++){ String code=ro.getCell("SubIndustryId", i); String codeName=ro.getCell("SubIndustryName", i); json.put(code, codeName); } } catch (JSONException e) { e.printStackTrace(); } out.print(json); out.close(); }
打印的json格式是
{"2701":"bb","1415":"aa"}
这次的异步请求就成功啦...