ajax 前台接收json 为undefined

来源:互联网 发布:js分割网址为数组 编辑:程序博客网 时间:2024/04/23 15:35
public ActionForward delCpId(ActionMapping mapping,ActionForm from,HttpServletRequest request,HttpServletResponse response)throws IOException{
String cpId = request.getParameter("cpId");
boolean flag = dao.delCpId(cpId);
JSONObject jo = new JSONObject();
jo.put("flag", flag);
PrintWriter out = response.getWriter();
out.write(jo.toString());
return null;

}

$.ajax({
url:path+"/btnCpConfigAction.do?act=delCpId",
data:{"cpId":cpId},
cache:false,
dataType:"json",//这里一定要写 返回的格式看上去是json  但不会以json格式接受
success:function(json){
var flag = json.flag;//没写dataType:'json'的话 这里的flag为undefined
if(flag){
$.messager.alert("提示","删除成功");
$('#mainPanel').datagrid('reload');
return;
}else{
$.messager.alert("提示","删除失败,请重新删除");
}
},
error:function(){
$.messager.alert("提示","网络错误,删除失败");
}
})


0 0