Php 使用JQuery发布序列化表单数据和额外变量

Php 使用JQuery发布序列化表单数据和额外变量,php,javascript,jquery,Php,Javascript,Jquery,我试图使用这段代码序列化表单,同时发送表单中未找到的额外变量。下面这行代码是我所期望的,但遗憾的是它不起作用 var thePage = theFilename(); $.post("pagedetail.php", { $("#PageDetailForm").serialize(), thePage: thePage }, function(data) { alert(data); }); 有什么想法吗?试试这个作为$的第二个参数。post: { form: $

我试图使用这段代码序列化表单,同时发送表单中未找到的额外变量。下面这行代码是我所期望的,但遗憾的是它不起作用

var thePage = theFilename();
$.post("pagedetail.php", { $("#PageDetailForm").serialize(), thePage: thePage },
    function(data) {
        alert(data); 
});

有什么想法吗?

试试这个作为
$的第二个参数。post

 { form: $("#PageDetailForm").serialize(), thePage: thePage }
尝试排序('toArray'):


希望您仍然需要这个:)。 尝试serializeArray()方法,然后在生成的数组中推送一些附加数据,这样就不会有拆分的数组等:

var postData = $('#form-id').serializeArray();
var additionalData = $('#additionalDataID').val();
postData.push({name: 'additionalName', value: additionalData});
最后:

$.post(URL, postData);

您可以做的是将额外的数据添加到隐藏的输入中,并在
pagedetail.php
page

请说出你的表格

   <form id='PageDetailForm'>
   <input type="hidden" name="value"  id="value" value="the value u wamnt to add goes here" />
             ....other inputs
</form>

如果您仍然混淆了hola me
@dplumptre

,希望能有所帮助。遗憾的是,这会将数据分成两个数组。一个有形状,一个有刺,另一个有刺。但这似乎并没有将页面添加到表单值的末尾。我在PHP中的打印只显示表单字段已提交:(.Close Through…还有其他想法吗???哦…我发现这是可行的:var serialized=$('#PageDetailForm')。serialize()+“&thePage=“+thePage;感谢您的帮助!!!然后尝试添加一个,它将与其余内容一起序列化。@Andy Barlow
$.post(URL, postData);
   <form id='PageDetailForm'>
   <input type="hidden" name="value"  id="value" value="the value u wamnt to add goes here" />
             ....other inputs
</form>
$.post("#pagedetail.php",$("#PageDetailForm").serialize(),function(data){

    $("#ans").html(data);

// in the pagedetail.php

$echo $_POST['value'];