Home >>jQuery Tutorial >jQuery serialize() Method

jQuery serialize() Method

jQuery serialize() Method

jQuery serialize() method in jQuery is used to creates a URL encoded text string by serializing form values (like input and/or text area) when making an AJAX request.

Syntax:
$(selector).serialize()
Here is an example of jQuery serialize() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".box1").text($("form").serialize());
});
});
</script>
</head>
<body>
<form action="">
First name: <input type="text" name="FirstName" value="Phptpoint"><br>
Last name: <input type="text" name="LastName" value="Training"><br>
</form>
<button class="btn1">Click me to Serialize form values</button>
<div class="box1"></div>
</body>
</html>

Output:
First name:
Last name:

No Sidebar ads