使用ajax提交form表单数据绑定
在ajax提交form表单,并实现数据绑定
定义function :
$.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if (o[this.name] !== undefined) { 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; };
//当表单中出现chexkbox(即有数组或集合属性),必须添加 traditional:true
//调用
var param= $("#owner-label-search-form").serializeObject();
$.ajax({ type: "GET", url: "XXX", data: param, //传入已封装的参数 dataType: "json", traditional: true,//必须指定为true success: function (result) { }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("查询失败"); } });

浙公网安备 33010602011771号