I would like to do something like this (pseudo code):
<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},
fun开发者_开发百科ction(){ alert('success!'); }
);
at the server side I want to get the fields from the form + page and ids
is it possible ?
You need to create the array of values with .serializeArray()
(where as .serialize()
creates a string) then add to it before using as the data
argument to $.post()
, like this:
var data = $("#testform").serializeArray();
data.push({ name: "abc", value: "1" });
data.push({ name: "ef", value: "3" });
$.post("test.php", data, function(){ alert('success!'); });
Then you pass in the array, just like passing in an object, and then $.param()
gets called internally, turning it into the data string for POST query.
精彩评论