form表单ajax提交,后台实体接收

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_20603425/article/details/83902244

js:表单->json对象


 

$.fn.serializeObject = function() {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [ o[this.name] ];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

$("#btn_save").click(function(){
        var formData = $("#archivecase").serializeObject();
        if (validform().form()) {
            $.ajax({
                url:"",
                type:"post",
                data:JSON.stringify(formData),
                contentType: "application/json",
                success:function(data){
                },
            })
        }
    })

controller:

@RequestMapping(value=" ",method=RequestMethod.POST)
    @ResponseBody
    public String addArchiveCase(@RequestBody Archive archive){

 

展开阅读全文

没有更多推荐了,返回首页