- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use jQuery.serializeArray() method to serialize data?
The serializeArray( ) method serializes all forms and form elements like the .serialize() method but returns a JSON data structure for you to work with.
Assuming we have following PHP content in serialize.php file −
<?php if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; $age = $_REQUEST['age']; echo "<br />Your age : ". $age; $sex = $_REQUEST['sex']; echo "<br />Your gender : ". $sex; } ?>
Example
The following is an example showing the usage of this method −
<html> <head> <title>The jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("#driver").click(function(event){ $.post( "/jquery/serialize.php", $("#testform").serializeArray(), function(data) { $('#stage1').html(data); } ); var fields = $("#testform").serializeArray(); $("#stage2").empty(); jQuery.each(fields, function(i, field){ $("#stage2").append(field.value + " "); }); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id = "stage1" style = "background-color:blue;"> STAGE - 1 </div> <br /> <div id = "stage2" style = "background-color:blue;"> STAGE - 2 </div> <form id = "testform"> <table> <tr> <td><p>Name:</p></td> <td><input type = "text" name = "name" size = "40" /></td> </tr> <tr> <td><p>Age:</p></td> <td><input type = "text" name = "age" size = "40" /></td> </tr> <tr> <td><p>Sex:</p></td> <td> <select name = "sex"> <option value = "Male" selected>Male</option> <option value = "Female" selected>Female</option> </select></td> </tr> <tr> <td colspan = "2"> <input type = "button" id = "driver" value = "Load Data" /> </td> </tr> </table> </form> </body> </html>
- Related Articles
- How to use POST method to send data in jQuery Ajax?
- How to use GET method to send data in jQuery Ajax?
- Node.js – v8.serialize() Method
- How to serialize Python dictionary to XML?
- How to specify the HTTP method to use when sending form-data in HTML?
- How to serialize a Python class?
- How to serialize a JavaScript array?
- A Preferred method to store PHP arrays (json_encode or serialize)?\n
- How to Use Customer Data Efficiently?
- How to use Java substring Method?
- How to serialize and de-serialize generic types using the Gson library in Java?\n
- How to serialize a lambda function in Java?
- How to serialize a Polygon object using FabricJS?
- How to use jQuery.wrapInner() method in jQuery?
- How to use jQuery.wrapAll() method in jQuery?

Advertisements