$("#saveBtn").click(function(){ var pid = $('input[name="parentId"]').val(); var pName = $('input[name="goodsTypeName"]').val(); var sort = $('input[name="sort"]').val(); var status = $('input[name="status"]:checked').val(); var path = "${path}/admin/goods/saveGoodsType"; $.ajax({ type:"POST", url:path, dataType:"json", contentType: "application/json; charset=utf-8", beforeSend:function(xhr) { xhr.setRequestHeader("If-Modified-Since","0"); xhr.setRequestHeader("Cache-Control","no-cache"); }, data:JSON.stringify({"parentId":pid,"typeName":pName,"sort":sort,"status":status}), //接送格式 beforeSend:function(xhr) { xhr.setRequestHeader("If-Modified-Since","0"); xhr.setRequestHeader("Cache-Control","no-cache"); }, success:function(result) { if(result.status == "success"){ genGoodsTypes(); /*div隐藏*/ $('#myModal').modal('hide') } } }); });
/** * 保存商品类型 * @param goodsType * @return * @throws Exception */ @RequestMapping(value="saveGoodsType",method=RequestMethod.POST) @ResponseBody public String saveGoodsType(@RequestBody GoodsType goodsType) throws Exception{ Mapmaps = new HashMap (); try { goodsTypeService.add(goodsType); maps = ajaxJsonMessage("success","添加商品类型成功!"); } catch (Exception e) { logger.error("添加商品类型发生错误!"); e.printStackTrace(); maps = ajaxJsonMessage("fail","添加商品失败!"); } return JSONObject.toJSONString(maps); }