以json形式提交form表单

自定义方法:
$.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;
};

提交方法:
function save(){
    var param  =  $("#form").serializeObject()
    $.ajax({
        url: "/save",
        type:'post',
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data:JSON.stringify(param),
    });
 }

你可能感兴趣的:(以json形式提交form表单)