- js函数:
$.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;
};
-
from 表单,不用action提交,用ajax 提交时,var json = $("#form1").serializeObject()
自动生成一个json对象。 -
在jsp 中将json 对象 转化成 json 字符串,JSON.stringify(json)