Obtain and submit form data Asynchronously

Source: Internet
Author: User

Asynchronous submission of form data has two pain points:

1. garbled Coding

In fact, the bottom layer of ajax technology is unicode encoding. garbled code occurs when GBK pages interact with interfaces. There are multiple solutions, which can convert the page to UTF-8 encoding, or encodeURI encoding twice before sending the data, decoding once when receiving the data.

2. Get form field data

Taking YUI3 as an example, the native io-form module has been well encapsulated. There is a private method named _ serialize, which can pre-encode the asynchronous form submission behavior:

Copy to ClipboardReference: [www.bkjia.com] data: encodeURI (Y. io. _ serialize ({
Id: '# formId ',
UseDisabled: true
}))

That is, a private method of zookeeper is used, which looks perfect. If the name attribute of a field does not contain special symbols such as [], it is normal.
The principle of this _ serialize method is very simple. You can retrieve input, select, textarea, and other fields in the node, and then traverse and set the value according to the name.

A simple code case (YUI3 ):

Copy to ClipboardReference: [www.bkjia.com] var parameters = [], nodeList;
NodeList. each (function (v ){
Parameters. push (v. get ('name') + '=' + Y. Lang. trim (v. get ('value ')));
});
Parameters = parameters. join ('&');

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.