serialize, serializeObject, serializeArray (ok)

http://jsfiddle.net/rFzyQ/

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://code.jquery.com/jquery.js"></script>
</head>

<body>
  <form id='postStatus'>
    <input name='somename' type='text' value='someval' />
  </form>
  <script type="text/javascript">
	  $.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;
	  };
	  var v = $("#postStatus").serializeObject();
	  console.log(v);
	  console.log($("#postStatus").serialize())
	  console.log($("#postStatus").serializeArray())
  </script>
</body>

</html>

Last updated

Navigation

Lionel

@Copyright 2023