Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我怎样才能通过完整的表格+;通过jquery$.post获得额外数据?_Jquery_Ajax_Jquery Post - Fatal编程技术网

我怎样才能通过完整的表格+;通过jquery$.post获得额外数据?

我怎样才能通过完整的表格+;通过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

我通过jquery$.post将表单中的数据发送到某个PHP页面,但现在我想向这个发送的包中添加一些额外的数据。 这是我的密码:

    $.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