Use the Ajax method to submit Form and note that ajaxform

Source: Internet
Author: User

Use the Ajax method to submit Form and note that ajaxform

Preface

When using form forms, once you click submit to trigger the submit event, the page Jump and inter-page Jump operations are usually controlled at the backend, the backend will control the page Jump and data transmission, but in some cases, you do not want the page to jump, or want to put the control on the front end, and use js to operate the page Jump or data changes.

In general, we all think of ajax for this asynchronous operation. Therefore, after implementing the function, we sorted out this article and used ajax to submit form and perform subsequent asynchronous operations.

Common form submission methods

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 

After you click the "Log on" button, a form submission event is triggered, and data is transferred to the backend. the backend controls the page Jump and data.

Form submission using ajax

After modification, the Code is as follows:

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 

Notes

  • In common modes, the type of the logon button is "submit;
  • In common methods, the form action is not empty;
  • The parameters in the $. ajax method are dataType and data.

I seldom write front-end code at ordinary times, that is, the entry level, which can be understood and changed. Therefore, Baidu is often used for many times. The implementation of this function also relies on Baidu. However, my Baidu code is at $. the value of the dataType parameter set in the ajax method is "html" instead of "json". As a result, I always reported an error during the initial debugging and finally changed it to "json, so here I would like to explain and remind you not to go wrong like me, but also the data value transmitted to the server, just like the code above, serialize the data in the form.

The above section describes how to use Ajax to submit Form forms and notes. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.