<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Title</title>
<script src= "Js/jquery.min.js" ></script>
<script type= "Text/javascript" >
(function ($) {
$.fn.serializejson=function (filter) {
var serializeobj={};
var array=this.serializearray ();
var str=this.serialize ();
$ (array). each (function () {
if (this.name!=filter) {
if (Serializeobj[this.name]) {
if ($.isarray (Serializeobj[this.name])) {
Serializeobj[this.name].push (This.value);
}else{
Serializeobj[this.name]=[serializeobj[this.name],this.value];
}
}else{
Serializeobj[this.name]=this.value;
}
}
});
return serializeobj;
};
}) (JQuery);
function ADDP () {
var json=$ ("#myform"). Serializejson ("Data");
JSON to String
Console.log (Json.stringify (JSON));
}
</script>
<body>
<form name= "MyForm" id= "MyForm" method= "POST" >
<div>
Name: <input type= "text" name= "pname" id= "PName"/>
Age: <input type= "text" name= "aged" id= "ages"/>
Interests: <textarea id= "interest" name= "interest" ></textarea>
</div>
<div>
<button type= "button" onclick= "ADDP ();" > Submit </button>
</div>
</form>
</body>
Convert form data to JSON format data