jQuery gets the form fields nicely and can then create objects containing the form fields,
var data = {"timeFlag":new Date()}; //Create an object var formDataStr = jQuery("#formGeneWholeModalQuery").serialize();//formGeneWholeModalQuery is the id of the form, and formDataStr is a string like userName=test&password=3241&age=54 var fmArr = formDataStr.split("&"); for(var i=0;i<fmArr.length;i++) { var fmF = fmArr[i]; var fmFarr = fmF.split("="); var key = fmFarr[0]; if(!isNullOrEmpty(fmFarr[1])) { eval("data."+key+"="+fmFarr[1]+";");//Write data.key directly, this is equivalent to data having a key attribute, you need to call eval to dynamically assign attributes } } data.queryType = type; //data already contains the value of each object
function isNullOrEmpty(field) { if(typeof field == undefined || typeof field == "undefined") return true; if(null==field || jQuery.trim(field).length<1) return true; return false; }