日期:2014-05-16  浏览次数:20478 次

在添加和编辑的时候,从后台的响应判断是否成功的JS写法
前台的逻辑判断
 function addSoftware(){
	var pno=$("#po_no_p").val();
	var cno=$("#contract_no_c").val();
	var url= "/support/pages/poapply/PoApply.do?actionFlag=searchSoftwareList&openWindowFlag=true&pFlag=inner&pno="+pno+"&cno="+cno+
	"&editFlag=${editFlag}&productLine=${pl}&product=${pp}&randomFlag="+new Date().getTime();
	var verifyurl = "/support/pages/poapply/PoApply.do?actionFlag=verifySoftwareList&pFlag=inner&pno="+pno+"&cno="+cno+"&randomFlag="+new Date().getTime();
	var a = "location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizables=yes,width="+(parseInt(screen.width)-15)+",height="+(parseInt(screen.height)-80)+",left=0,top=0";
	if(pno!=""||cno!=""){
  	  $.ajax({
  		url:verifyurl,
  		async: false,
  		type: "GET",
  		dataType: "json",
  		success: function(data){  				 	  var str = data.reslut;
  		  if("OK"==str){
  		    window.open(url,null,a);
  		  }else{
  		     alert("<bean:message key="support.po.app.noIsNotExit"/>");
  		  }			 
  	         },
  		error: function(){
		alert("<bean:message key="sys.err.unknowerror"/>");
		}
	 });
	}else{
	  alert("<bean:message  key="support.po.app.enterNo"/>");
	   return;	
	}	     	
}	

前台能拿到var str = data.reslut;后台的标示是需要在后台作如下的操作的,相关的代码如下:
    /**
      * @since SPC800
     * @throws Exception
     *             Exception
     * @param mapping
     *            mapping
     * @param form
     *            form
     * @param request
     *            request
     * @param response
     * 此方法为用户在点击查询按钮的时候调用的Ajax验证方法,如果没有数据则不允许open window
     */
    @SuppressWarnings("unchecked")
    public ActionForward verifySoftwareList(ActionMapping mapping,
        ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception
    {
        HttpSession session = request.getSession(false);
        PrintWriter out = response.getWriter();
        //语种
        String nls = (String) session.getAttribute(SupportConstants.CFG_NLS);
        //界面上获取订单号
        String pno = request.getParameter("pno").trim();
        //界面上获取合同号
        String cno = request.getParameter("cno").trim();        
        JSONObject jsonObj = new JSONObject();
        jsonObj.put(PoApplyConstants.NLS_LANG, nls);
        jsonObj.put(PoApplyConstants.CONTRACT_NO, cno);
        jsonObj.put(PoApplyConstants.PO_NO, pno);
        jsonObj.put(PoApplyConstants.IFSELECTED, "VERIFY");
        //调用WebService的后台接口
        IPoApplyWs poApplyWs = new IPoApplyWsProxy();
        String resultStr =
            poApplyWs.getRelatedSwDetailListById(jsonObj.toString());
        String str = "";
        if (null != resultStr && !"0".equals(resultStr))
        {
            //"OK "
            str  = "{\"reslut\":\"OK\"}";
            out.write(str);
            //out.write("OK");
        }
        else
        {
            str  = "{\"reslut\":\"FAILED\"}";
            out.write(str);            
          //  out.write("FAILED");
        }
        return null;
    }