Home >Web Front-end >Front-end Q&A >What does serialization mean in jquery

What does serialization mean in jquery

青灯夜游
青灯夜游Original
2023-03-20 11:01:421919browse

In jquery, serialization refers to the process of converting an object into a transmittable byte sequence. Serialization is to solve the problems caused by reading and writing object streams; serialization is a mechanism used to process object streams. The so-called object stream is to stream the content of the object.

What does serialization mean in jquery

The operating environment of this tutorial: windows7 system, jquery3.6 version, Dell G3 computer.

What does serialization mean?

is a mechanism used to process object streams. The so-called object stream is to process the contents of objects. Fluidize. The streamed objects can be read and written, and the streamed objects can also be transmitted between networks. Serialization is to solve the problems caused when reading and writing object streams.

  • Serialization: The process of converting an object into a transmittable byte sequence is called serialization.

  • Deserialization: The process of restoring a byte sequence into an object is called deserialization.

Why serialize?

If you just look at the definition, I think it is difficult for you to understand the meaning of serialization at once. Then we can deduce what serialization is from another angle. So what is the purpose of serialization?

In fact, the ultimate purpose of serialization is to allow objects to be stored across platforms and transmitted over the network. The way we carry out cross-platform storage and network transmission is IO, and the data format supported by our IO is byte array.

Because it is not enough for us to unilaterally convert the object into a byte array, because without a regular byte array we cannot restore the original appearance of the object, so we must convert the object into When creating a byte array, we formulate a rule (serialization), then when we read the data from the IO stream, we use this rule to restore the object back (deserialization).

If we want to transport a house from one place to another, serialization means that I break the house into bricks and put them in the car, and then leave a picture of the original structure of the house. Drawings, deserialization is the process of restoring the bricks to the original appearance of the house according to the drawings after we transport the house to the destination

jQuery serialization method

There are two types of serialization in jQuery: serialize() method and serializeArray() method.

1. serialize() method:

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

You can select one or more form elements (such as input and/or text box), or the form element itself.

The serialized value can be used in the URL query string when generating an AJAX request. In this way, when ajax submits form data, there is no need to list each parameter one by one. You only need to set the data parameter to: $ ("form").serialize() will do.

What does serialization mean in jquery

Output standard query string: a=1&b=2&c=3&d=4&e=5

Note: Only the "successful control" sequence will be into a string. (That is, elements that are not disabled) If a button is not used to submit the form, the value of the submit button is not serialized. If you want a form element's value to be included in a sequence string, the element must use a name attribute.

2. serializeArray() method:

The 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.

What does serialization mean in jquery

This method returns a JSON object instead of a JSON string.

The returned JSON object is composed of an array of objects, where each object contains one or two name-value pairs - name parameter and value parameter (if value is not empty).

Elements cannot be disabled (disabled elements will not be included), and the element should have a name attribute. The submit button's value is also not serialized. Data for file selection elements is also not serialized.

Note: 1. Not disabled; 2. Contains name attribute

[Recommended learning: jQuery video tutorial, web front-end video]

The above is the detailed content of What does serialization mean in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn