Web/Javascript
html form을 json으로 변환
bboks.net
2016. 2. 17. 15:42
serializeObject 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; };
호출
$.ajax({ url : 'url', contentType: 'application/json', data : JSON.stringify($("form").serializeObject()), type : 'POST', dataType : 'json', success : function(result) { ..... } });