我想做这样的事情(伪代码): form id='f1'input type='text' name='t1'/input type='text' name='t2'/input type='text' name='t3'//form var ids=[9,32,45];$.post("test.php", {$("#testform").serialize(), page: 7, ids: ids}, function(){ a
<form id='f1'> <input type='text' name='t1'/> <input type='text' name='t2'/> <input type='text' name='t3'/> </form>
var ids=[9,32,45];
$.post(
"test.php",
{$("#testform").serialize(), page: 7, ids: ids},
function(){ alert('success!'); }
);
在服务器端,我想从表单页面和ID中获取字段
可能吗 ?
您需要使用.serializeArray()创建值数组(其中
.serialize()创建一个字符串)然后在用作
$.post()的数据参数之前添加到它,如下所示:
var data = $("#testform").serializeArray();
data.push({ name: "abc", value: "1" });
data.push({ name: "ef", value: "3" });
$.post("test.php", data, function(){ alert('success!'); });
然后传入数组,就像传入一个对象一样,然后在内部调用$.param(),将其转换为POST查询的数据字符串.
