我怎样才能通过完整的表格+;通过jquery$.post获得额外数据?
我通过jquery$.post将表单中的数据发送到某个PHP页面,但现在我想向这个发送的包中添加一些额外的数据。 这是我的密码:我怎样才能通过完整的表格+;通过jquery$.post获得额外数据?,jquery,ajax,jquery-post,Jquery,Ajax,Jquery Post,我通过jquery$.post将表单中的数据发送到某个PHP页面,但现在我想向这个发送的包中添加一些额外的数据。 这是我的密码: $.post("/settings/filter", $("#filter_form").serialize() , function(data,status,xhr) { my_data = data; }) 我试着把它改成 $.post("/settings/filter", {$("#filter_f
$.post("/settings/filter", $("#filter_form").serialize() , function(data,status,xhr)
{
my_data = data;
})
我试着把它改成
$.post("/settings/filter", {$("#filter_form").serialize(), extra_variable:'extra1'} , function(data,status,xhr)
但是这是错误的,怎么做呢?你可以使用字符串压缩
$("#filter_form").serialize() + '&extra_variable=extra1'
这是因为
$(“#filter_form”).serialize()
返回表单的字符串表示形式,如params1=x¶ms2=y
,如果数据是字符串,则jQuery将不会对数据进行更多处理。因此,您需要执行字符串连接以附加所需的额外值。您可以使用字符串连接
$("#filter_form").serialize() + '&extra_variable=extra1'
这是因为
$(“#filter_form”).serialize()
返回表单的字符串表示形式,如params1=x¶ms2=y
,如果数据是字符串,则jQuery将不会对数据进行更多处理。因此,您需要执行字符串连接以附加所需的额外值。您可以使用$(“#filter_form”).serialize()+'&extra_variable=extra 1'
您可以使用$(“#filter_form”).serialize()+'&extra_variable=extra 1'
如果我想添加额外数组?如果您想传递数组a=[1,2,3]
[]=3如果我想添加额外的数组?如果你想传递数组a=[1,2,3]
那么a[]=1&a[]=2&a[]=3