以json形式提交form表單
阿新 • • 發佈:2019-02-07
自定義方法: $.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),}); }