1. 程式人生 > >以json形式提交form表單

以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),});
}