ajax serializeArray() method


  Translation results:

serialize

UK[ˈsɪəriəlaɪz] US[ˈsɪriəlaɪz]

vt. Serialization, serialization (story)

array

UK[əˈreɪ] US[ə'reɪ]

n.Array;queue,array;a large number;clothes

vt.arrangement;deployment of troops;dressing, decorate

ajax serializeArray() methodsyntax

Function: serializeArray() method creates an object array (name and value) by serializing form values. You can select one or more form elements (such as input and/or textarea), or the form element itself.

Syntax: $(selector).serializeArray()

Description: serializeArray() method serializes form elements (similar to .serialize() method), returns JSON data structure data.

Note: This method returns a JSON object rather than a JSON string. You need to use a plug-in or third-party library for stringification operations. The returned JSON object consists of an array of objects, each of which contains one or two name-value pairs - a name parameter and a value parameter (if value is not empty).

ajax serializeArray() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    x=$("form").serializeArray();
    $.each(x, function(i, field){
      $("#results").append(field.name + ":" + field.value + " ");
    });
  });
});
</script>
</head>
<body>
<form action="">
First name: <input type="text" name="FirstName" value="Bill" /><br />
Last name: <input type="text" name="LastName" value="Gates" /><br />
</form>

<button>序列化表单值</button>
<div id="results"></div>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A