(傲娇的白狐)前端获取json数据 个人记录
前端获取json数据 后端写成这样的话
@RequestMapping("/insertreimbursement")
@ResponseBody
public String insertreimbursement(Reimbursement reimbursement,HttpSession session){
略。。。。。。。。。。。。。。。。。。。。
if(i != 0){
jsonData = JsonData.buildSuc("添加成功,等待审核");
}else {
jsonData = JsonData.buildError("错误");
}
System.out.println("JSON.toJSONString(json) = " + JSON.toJSONString(jsonData));
System.out.println("jsonData = " + jsonData);
return JSON.toJSONString(jsonData);
}
返回的是 string类型的 而一些前端框架 会把strign 转换为ison类型 普通使用要 这样
$.post({ url:'/reimbursement/insertreimbursement', data:{'description':description, 'tyname':tyname,'TypesId':typesId,'money':money,'certificate':im }, success:function (re) { var jsonobj= eval('(' + re + ')'); console.log(re) console.log(jsonobj) console.log(typeof re) console.log(jsonobj.msg) if(re.code==200){ alert(re.msg) window.location.href="/page/defaut"; return false; }else { alert(re.msg); return false; } } },"json")
本博客仅为个人记录,作为日记式博客。如有错误不足请指出,感谢。

浙公网安备 33010602011771号