A detailed description of the Ajax method to implement form form submission and considerations

Source: Internet
Author: User
When using form form, once click Submit Trigger Submit event, will generally make the page jump, page jumps and other behavior control often in the back end, the backend will control the page jump and data transmission, but at some point do not want the page to jump, or want to put control on the front, Through JS to manipulate the page jump or data changes. This article mainly introduces the use of Ajax method to implement form form submission and attention, the need for friends can refer to, hope to help everyone.

In general, this asynchronous operation, we will think of the AJAX approach, so after the implementation of the function of this article, through the Ajax method to implement the form form the submission and subsequent asynchronous operation.

Common Form form submission methods

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

Click the login button, that is, trigger the form of the submission of the event, data transfer to the backend, the back-end control page jump and data.

Ajax implementation Form Submission method

After the modification is complete, the code is as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

Precautions

    • In the usual way, the type of the login button clicked is "Submit";

    • In the common way, the action of form is not empty;

    • The Ajax way to note is the parameters in the $.ajax method: DataType and data.

I usually rarely write front-end code, level is the entry level, can read can change it, so many times are Baidu, like this feature of the implementation is also with the help of Baidu, but, I Baidu to the code in the $.ajax method set the datatype parameter value is "HTML" instead of "JSON", Cause I at the beginning of debugging at the time of the error, and finally changed to "JSON" to succeed, so here specifically and remind me, do not go the wrong way with me, there is the data value transmitted to the server, like the above code, the form of the data in the form of a serialized transfer.

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.