jQuery > Ajax methods

.serialize() - Serialize html form data in jQuery

How to serialize the html form data that can be submitted to the server in jQuery?


To serialize (URL Encod) the html form data that can be sent to the server, serialize() method can be used.

<form method="post" action="somepage.html">
<input type="button" id="btnSerialize" value="Serialize data" /> <textarea id="txtArea1" name="txtArea1" rows="10" cols="50"></textarea> </form>
<script> $("#btnSerialize").click(function () { var data = $("form").serialize(); $("#divData").val(data); }); </script>

In the above code snippet, on click button “btnSerialize”, all the form element and its data will be serialized into a string that can be sent to the server. In this case, after serializing, we are writing that data into "divData" element.

 Views: 8740 | Post Order: 111



Write for us






Hosting Recommendations