我有以下表格:
var formData = new FormData($('#form')[0]);
var formTRData = new FormData($('#form_tr')[0]);
var formTLData = new FormData($('#form_tl')[0]);
var formBRData = new FormData($('#form_br')[0]);
var formBLData = new FormData($('#form_bl')[0]);
然后我发送:
$.ajax({
url: 'aaaaa.php',
type: 'POST',
data: ????
如何发送数据中的所有表格?
答案 0 :(得分:0)
您像这样传递数据 数据:{name:'Wayne',年龄:27,国家/地区:'Ireland'}, 如您所见,首先是参数的标识符,然后是冒号和实际数据。
在您的aaaaa,php中,您可以通过以下方式访问参数
$name = $_POST['name'];
$age = $_POST['age'];
$country = $_POST['country'];
这应该有帮助
答案 1 :(得分:0)
创建一个包含所有此类对象的对象:
var data = {
"formData": new FormData($('#form')[0]);
"formTRData": new FormData($('#form_tr')[0]);
"formTLData": new FormData($('#form_tl')[0]);
"formBRData": new FormData($('#form_br')[0]);
"formBLData": new FormData($('#form_bl')[0]);
}
确保服务器端准备好接收复杂的对象并正确解析它。
答案 2 :(得分:0)
您可以使用$ .param()组合对象:
declare @Table_I table (I_ID int, Value varchar(10), Ischecked bit, Region varchar(2))
insert into @Table_I values (1, 'A', 0, 'N1'), (2, 'B', 1, 'N1'), (3, 'C', 0, 'N2')
declare @Table_PB table (PB_ID int, Region varchar(2), Code varchar(2))
insert into @Table_PB values (1, 'N1', 'A1'), (2, 'N1', 'A2'), (3, 'N1', 'A3'), (4, 'N2', 'C1')
declare @Table_D table (D_ID int, I_ID int, PB_ID int)
insert into @Table_D values (1, 1, 1), (2, 1, 2), (3, 3, 1), (4, 3, 4)
select i.I_ID, i.Value, i.IsChecked, i.Region, d.PB_ID, pb.Code
from @Table_I i
left outer join @Table_D d on i.I_ID = d.I_ID
left outer join @Table_PB pb on d.PB_ID = pb.PB_ID
答案 3 :(得分:0)
var formData = new FormData($('#form')[0]);
var formTRData = new FormData($('#form_tr')[0]);
var formTLData = new FormData($('#form_tl')[0]);
var formBRData = new FormData($('#form_br')[0]);
var formBLData = new FormData($('#form_bl')[0]);
var formDataEntries = formData.entries();
var formTRDataEntries = formTRData.entries();
var formTLDataEntries = formTLData.entries();
var formBRDataEntries = formBRData.entries();
var formBLDataEntries = formBLData.entries();
var data = [...formDataEntries, ...formTRDataEntries, ...formTLDataEntries, ...formBRDataEntries, ...formBLDataEntries];
您可以将扩展运算符用于formData迭代器。
答案 4 :(得分:0)
解决方案是:
var formData = new FormData($('#form')[0]);
$.each($('#form_tr')[0], function(i, e) {
formData.append(e.name, e.value);
});
$.each($('#form_tl')[0], function(i, e) {
formData.append(e.name, e.value);
});
$.each($('#form_br')[0], function(i, e) {
formData.append(e.name, e.value);
});
$.each($('#form_bl')[0], function(i, e) {
formData.append(e.name, e.value);
});