getJson
$.getJSON("<%=basePath%>delivery/auditing.do",{Phones:Phones,currPage:currPage,timstamp:timstamp}, function(data){ alert(data); if(data==1){ alert("设置成功"); window.location.href="<%=basePath%>delivery/expressinfo.do?currPage="+currPage; }else if(data==2){ alert("请先增加计费信息!"); window.location.href="<%=basePath%>delivery/expressinfo.do?currPage="+currPage; }else { alert("设置失败"); window.location.href="<%=basePath%>delivery/expressinfo.do?currPage="+currPage; } });
在 .getJSON 中,可以 传递 Phones 这个参数,在java servlet 接口中接收参数。 根据逻辑做处理,通过 pw.print(2) 返回不同的 data 值:
@RequestMapping(value="/delivery/auditingSuccess.do") public void auditingSuccess(HttpServletRequest request,HttpServletResponse response) throws Exception{ response.setContentType("text/html"); request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); String Phones =request.getParameter("Phones"); String currPage=request.getParameter("currPage"); …… if (null == expressPrice) { PrintWriter pw = response.getWriter(); pw.print(2); pw.flush(); pw.close(); return ; } else if(i == ids.length ){ PrintWriter pw = response.getWriter(); pw.print(1); pw.flush(); pw.close(); } }