Home > Web Front-end > JS Tutorial > body text

How to use the jQuery ajax serialize() method and solve common problems_jquery

WBOY
Release: 2016-05-16 17:42:37
Original
1308 people have browsed it

When using ajax, you often need to assemble the input data in the form of 'name=abc&sex=1'. This work can be easily completed using JQuery's serialize method!

jQuery ajax - serialize() method definition and usageserialize() method creates a URL-encoded text string by serializing form values.
You can select one or more form elements (such as inputs and/or text boxes), or the form element itself.
Serialized values ​​can be used in URL query strings when generating AJAX requests.

jQuery ajax - serialize() method syntax
$(selector).serialize()
jQuery ajax - serialize() method detailed description

.serialize() method is created with A text string represented in standard URL encoding. It operates on a jQuery object that represents a collection of form elements.

jquery ajax - serialize() method There are several types of form elements:

Copy code The code is as follows:












< ;/form>

The
.serialize() method can operate on jQuery objects that have selected individual form elements, such as ,


Use: $("#form1").serialize();
Result: name1=pipi&name2=1&name3=test
There is a problem with jQuery ajax - serialize() method
If the following situation occurs:

Copy code The code is as follows:





Use:$("#form1").serialize();
Result: name1=pipi&blog=blue submarine
How can I change the number back to a space?
There is one last question, as shown below:

Copy the code The code is as follows:






사용: $("#form1").serialize();
결과: blog=blue Submarine은 나타날 수 없습니다. length=pipi
이유는 length가 js 배열의 속성 키워드이고 충돌이 발생하지 않는 다른 문자열로 이름을 변경하면 됩니다.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template