serialize to object jquery code example
Example 1: jquery form serialize object
$(function(){
$('form').on('submit', function(e){
e.preventDefault();
$(this).serializeObject().done(function(o){
if(window.console) console.log(o);
var j = JSON.stringify(o);
alert(j);
});
});
});
Example 2: get serialize data javascript
<form id="myForm" name="myForm">
<div>
<label for="username">Enter name:</label>
<input type="text" id="username" name="username">
</div>
<button type="button" onclick="clickMe()">Click</button>
</form>
function clickMe(){
let myForm = document.getElementById('myForm');
let formData = new FormData(myForm);
console.log(formData.get('username'));
}