Jquery Ajax方法传值到action的方法

JSP页面内容

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/lib/include/taglibs.jsp" %>
<html>
<head>
    <title>站点信息审核</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <%@ include file="/lib/include/jquery.jsp" %>
    <%@ include file="/lib/include/ligerUI.jsp" %>
    <link href="${themectx}/css/custom.css" rel="stylesheet"/>
</head>

<body>
<div style="padding-left: 10px; float: left;  " id="usergrid">
    <div class="l-toolbar" style="width: 780px">
        <div class="l-toolbar-item l-panel-btn" id="btnSave">
				<span>
					<i class="fa fa-save"></i>
					<span>保存</span>
				</span>
        </div>

        <div id="loader" style="height: 46px; width: 40px; right: 10px; top: 1px; position: absolute;"></div>
    </div>
    <div id="mainContain" class="right_tabs_content" style="width: 765px">
        <div class="basic-grey" id="divbaseinfContain">

            <label>
                <span>资源系统站址编码 :</span>
                <input id="baseStationCode" type="text" value="" />
            </label>
            <label>
                <span>站点名称 :</span>
                <input id="baseStationName" type="text" value=""/>
            </label>
            <label>
                <span>审核人 :</span>
                <input id="examineName" type="text" value=""/>
            </label>
            <label>
                <span>审核时间 :</span>
                <input id="examineTime" class="form-control-inline Wdate useTag" οnfοcus="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})" type="text" placeholder="" value="">
            </label>

            <label>
                <span>审核是否通过 :</span>
                <input name="chkState" type="radio" id="chkPass" style="width: 18px;height: 18px;position: relative" value="审核通过">
                <span style="float: none;margin-top: 10px;position: relative">审核通过</span>
                <input name="chkState" type="radio" id="chkNoPass" style="width: 18px;height: 18px;position: relative" value="审核不通过">
                <span style="float: none;margin-top: 10px;position: relative">审核不通过</span>
            </label>
            <br style="clear:both">
            <label>
                <span>审核意见 :</span>
                <textarea id="examineRemark"></textarea>
            </label>
        </div>
    </div>
</div>
<script src="/lib/leshan/js/stationInfo/stationInfo_stationCheck.js" type="text/javascript"></script>
</body>
</html>


JS页面:

$(function () {
    $("#btnSave").click(function () {//按钮id是btnSave,这里改下
        saveData();
    });
});

//保存数据
function saveData() {
    if (!dataValidation()) {
        DialogUtil.showInfo("输入的表单数据有误!");
        return false;
    }
    var data = getData();
    $.ajax({
        url: "/leshan/stationInfo_addStationCheckMessage.do",//对应到站点信息审核的获取方法
        type: "post",
        async: false,
        data: {"jsondata": $.toJSON(data)},
        dataType: "json",
        contentType: "application/x-www-form-urlencoded",
        success: function (response, textStatus, jqXHR) {
            if (!!response) {
                if (response.isSuccess) {
                    DialogUtil.showInfo("保存数据成功");
                }
                else {
                    if (!!response.msg) {
                        DialogUtil.showErrorWithInfo("保存数据失败", response.msg);
                    } else {
                        DialogUtil.showError("保存数据失败");
                    }
                }
            }
        }
    });
}

//验证数据,看下是否需要验证数据
function dataValidation() {
    return true;

}

//获取表单数据
function getData() {
    var data = {
        baseStationCode: $("#baseStationCode").val(),//资源系统站址编码
        baseStationName: $("#baseStationName").val(),//站点名称
        examineName: $("#examineName").val(),//审核人
        examineTime: $("#examineTime").val(),//审核时间
        chkPass: $('input:radio:checked').val(),//获取审核通过的按钮值
        examineRemark: $("#examineRemark").val()//审核意见
    }
    return data;
}


Action处理:
package com.gcidesign.erp.platform.leshan.action;

import com.alibaba.fastjson.JSON;
import com.gcidesign.erp.core.web.action.BaseAction;
import com.gcidesign.erp.platform.leshan.service.StationInfoManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * Created on 2017/8/14.
 */
@Controller(value = "stationInfoAction")
@Scope(value = "prototype")
public class StationInfoAction extends BaseAction {
    private final static Logger logger = LoggerFactory.getLogger(StationInfoAction.class);

    @Autowired
    private StationInfoManager stationInfoManager;

    /**
     * 站点信息审核
     */
    public String stationCheck() {
        return SUCCESS;
    }

    /**
     * 站点审核信息的获取
     */
    public void addStationCheckMessage(){

            String jsondata = request.getParameter("jsondata");

            Object succesResponse = JSON.parse(jsondata);
            Map<String,String> data = (Map<String,String>)succesResponse;

            String baseStationCode = data.get("baseStationCode");
            String baseStationName = data.get("baseStationName");
            String examineName = data.get("examineName");
            String examineTime = data.get("examineTime");
            String chkPass =  data.get("chkPass");
            String examineRemark = data.get("examineRemark");
            System.out.println("资源站址编码为:"+baseStationCode+";站点名称为:"+baseStationName+";审核人为:"+examineName);
            System.out.println("审核时间为:"+examineTime+";审核结果为:"+chkPass+";审核意见为:"+examineRemark);

            result.setEntity(data);
            renderJsonToResponse(result);


    }
}





 


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值