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.