您可以连接两个表单数据,如下所示:
$.ajax({
url: '/submit_form_data.php',
type: 'POST',
data: $("#form1").serialize() + '&' + $("#form2").serialize() ,
success: function(response) {
// Handle the response from the server.
}
});
我得到的工作解决方案为:
$(document).ready(function() {
// Create a FormData object for each form.
var formData1 = new FormData($('#form1')[0]);
var formData2 = new FormData($('#form2')[0]);
// Append the FormData objects to a single object.
var formData = new FormData();
formData.append('formData1', formData1);
formData.append('formData2', formData2);
// Make an Ajax request to the server, passing in the FormData object as the data parameter.
$.ajax({
url: '/submit_form_data.php',
type: 'POST',
data: formData,
processData: false, // Don't process the data as a query string.
contentType: false, // Don't set the Content-Type header.
success: function(response) {
// Handle the response from the server.
}
});
});