当前位置:编程学习 > JS >>

关于jQuery获取Action返回的JSON数据 项目真实案例 记录

这里列出 页面代码 和 Action类相关代码 供参考:

 

页面代码(jQuery ajax异步请求获取数据):

 

[javascript]
<span style="font-family:Microsoft YaHei;font-size:13px;">//保存决策信息 
    function saveDecision() { 
        var rowid = checkSelected(); 
        var rowData = jQuery("#list").jqGrid('getRowData', 
                rowid); 
        var processIsRight = rowData["processIsRight"]; 
        if(rowid==-1){ alert("只能选择一个推荐方案");return; } 
        else if(processIsRight==0){//检查流程是否存在问题 
            alert("该流程方案下有任务无岗位默认人,请仔细检查该流程方案");return; 
        } 
        //判断是否选择了决策人:必选 
        var _decisionMaker = $("#businessModule").find("option:selected").val(); 
        if(_decisionMaker=='' || _decisionMaker == "undefined") { alert("请选择一个决策人!"); return;} 
        else if(rowid>0){ 
        var url = "saveDecision.action?" + getParams(); 
        //document.write(url); 
        alert(url); 
        /***/ 
        $.ajax({ 
            url : url, 
            type : 'POST', 
            dataType : 'json', 
            success : function(json) { 
                //reference: http://blog.csdn.net/jpr1990/article/details/6931027 
                alert(json); 
                window.close(); 
            }, 
            error : function() { 
                alert('数据加载失败,请重试..'); 
                //window.close(); 
            } 
        }); 
         
        }else{ 
            alert("请选择一个推荐方案");return; 
        } 
    }</span> 

后台Action类相关代码(主要是看怎样返回JSON数据):

[java]
<span style="font-family:Microsoft YaHei;font-size:13px;">/**
     * 保存决策信息
     *  
        0 - 未启动. 
        1 - 暂停.
        2- 运行中. 
        3 - 失败. 
        4 - 终止. 
        5 - 完成. 
        6 - 已删除.
     */ 
    public String save() { 
        if (assistDecision != null) { 
            try { 
                // 生成实际决策时间 
                Timestamp decision_date = new Timestamp(System.currentTimeMillis());// 不能大于强制决策时间,还没有做判断 
                 
                assistDecision.setDecisionMaker(assistDecision.getDecisionMaker()); 
                 
                assistDecision.setDecisionTime(decision_date); 
                //判断是否自动启动流程 
                if(this.getIsStartProcess().equals("true")){ 
                    assistDecision.setSolutionState(2);// 设置SolutionState 为:2-运行中 
                    this.decisionExecutorService.saveAssistDecision(assistDecision,true,processId,emgencyInfoProcessId); 
                }else{ 
                    assistDecision.setSolutionState(0);// 设置SolutionState 为:0-未启动 
                    this.decisionExecutorService.saveAssistDecision(assistDecision,false,processId,emgencyInfoProcessId); 
                } 
                jsonMassage = "决策成功,数据已保存!"; 
            } catch (Exception e) { 
                e.printStackTrace(); 
                jsonMassage = "该流程方案下有任务无岗位默认人,请仔细检查该流程方案"; 
                System.out.println(jsonMassage); 
                return SUCCESS; 
            } 
        } 
        return SUCCESS; 
&nb

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,