Description:
The Jquery serialize() method creates a URL encoded text string by serializing form values. It is used in form controls like <input>, <textarea>, <select> etc.. It serializes the form values so that its serialized values can be used in the URL query string while making an AJAX request.
Syntax
$(selector).serialize()
No Arguments | This method does not accept any arguments. |
Example:
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function () { $("#btnSubmit").click(function () { $("#divOutpu").text($("form").serialize()); }); }); </script> </head> <body> <form> Enter Your First name: <input type="text" name="FirstName"><br> Enter Your Last name: <input type="text" name="LastName"><br> Enter Your Age: <input type="text" name="Age" style="margin-left:35px;"><br> </form> <br> <button id="btnSubmit">Serialize form values</button><br><br> <div id="divOutpu" style="background-color:#6fb5ef; font-size:large; width:600px;color:black;"></div> </body> </html>
Output: