jQuery serialize()

Introduction

Output the result of serialized form values:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from w  ww .j  a v  a2 s .  co m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
      $("div").text($("form").serialize());
  });
});
</script>
</head>
<body>

<form action="">
  First name: <input type="text" name="FirstName" value="CSS"><br>
  Last name: <input type="text" name="LastName" value="HTML"><br>
</form>

<button>Serialize form values</button>

<div></div>

</body>
</html>

The serialize() method creates a URL encoded text string by serializing form values.

The serialized values can be used in the URL query string when making an AJAX request.

$(selector).serialize()



PreviousNext

Related