JQuery uses serialize () to submit form data based on ajax () _ jquery

Source: Internet
Author: User
This article mainly introduces how jQuery uses serialize () to submit form data based on ajax, combined with the instance form, this paper analyzes in detail the techniques of jQuery Using ajax to submit serialized form data, which has some reference value, for more information about how jQuery uses serialize () to submit form data, see the following example. We will share this with you for your reference. The details are as follows:

The serialize () method of jQuery creates a URL encoded text string by serializing the form value. We can select one or more form elements or directly select form to serialize them, for example:

《script》$(document).ready(function(){ console.log($("form").serialize()); // FirstName=Bill&LastName=Gates});《script》

In this way, we can pass the serialized value to ajax () as the url parameter and use ajax () to submit the form, instead of getting the values in the form one by one and passing them to ajax (), the example is as follows:

$.ajax({ type: 'post', url: 'your url', data: $("form").serialize(), success: function(data) {  // your code }});

The use of $. post (), $. get (), and $. getJSON () is the same:

$.post('your url', $("form").serialize(), function(data) {  // your code }});$.get('your url', $("form").serialize(), function(data) {  // your code }});$.getJSON('your url', $("form").serialize(), function(data) {  // your code }});

I hope this article will help you with jQuery programming.

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.