Serialize Form to JSON


/ Published in: jQuery
Save to your folder(s)

usage; $.toJSON($(\'form\').serializeObject());


Copy this code and paste it in your HTML
  1. $.fn.serializeObject = function()
  2. { //Prepping for JSON
  3. var o = {};
  4. var a = this.serializeArray();
  5. $.each(a, function() {
  6. if (o[this.name]) {
  7. if (!o[this.name].push) {
  8. o[this.name] = [o[this.name]];
  9. }
  10. o[this.name].push(this.value || '');
  11. } else {
  12. o[this.name] = this.value || '';
  13. }
  14. });
  15. return o;
  16. };

URL: http://tobiascohen.com/files/stackoverflow/jquery-form-serializeObject.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.