Serialize( ) method
The serialize( ) method serializes a set of
input elements into a string of data. So we can say thatThe serialize() method
creates a URL encoded text string by serializing form values.You can select one
or more form elements (like input and/or text area), or the form element
itself.The serialized values can be used in the URL query string when making an
AJAX request.
Syntex:
|
$.serialize( )
|
Example:
|
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").text($("form").serialize());
});
});
</script>
</head>
<body>
<form action="">
First name:
<input type="text" name="FirstName"
value="Nitin"><br>
Last name:
<input type="text" name="LastName"
value="Chauhan"><br>
</form>
<button>Serialize form value</button>
<div></div>
</body>
</html>
|