我可以为这种形式做serializeArray- ?
$(document).on("click", ".rq-submit", function(e){
var formData = $(this).parents("form").serializeArray();
formData.push({name: 'act', value: act});
formData.push({name: 'rqID', value: rqID});
});
HTML
<form id="rq-form-2" action="#" method="post" class="rq-form ">
<input type="text" name="rq[name]">
<input type="text" name="rq[email]">
<input class="btn btn-success rq-submit" data-act="edit" value="SUBMIT" type="submit" >
</form>
答案 0 :(得分:1)
如果您要发送作为ajax默认内容类型的url编码表单数据以及浏览器如何发送表单,则可以使用serialize()
和$.param()
来序列化对象
$(document).on("submit", ".rq-form", function(e){
e.preventDefault();
var extraParams ={
act:22,
rqId:44
}
var formData = $(this).serialize();
var postData = formData +'&'+ $.param(extraParams);
console.log(postData);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="rq-form-2" action="#" method="post" class="rq-form ">
<input type="text" name="rq[name]" value="foo">
<input type="text" name="rq[email]" value="bar">
<input class="btn btn-success rq-submit" data-act="edit" value="SUBMIT" type="submit" >
</form>