jQuery:serialize()表单和其他参数 [英] jQuery: serialize() form and other parameters
本文介绍了jQuery:serialize()表单和其他参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以发送 form 元素(使用 .serialize()
方法)和其他具有单个AJAX请求的参数?
Is it possible to send form elements (serialized with .serialize()
method) and other parameters with a single AJAX request?
示例:
$.ajax({
type : 'POST',
url : 'url',
data : {
$('#form').serialize(),
par1 : 1,
par2 : '2',
par3: 232
}
}
如果不是,将表单与其他参数一起提交的最佳方法是什么?
If not what's the best way to submit a form together with other parameters?
谢谢
推荐答案
serialize()
有效地将表单值转换为有效的查询字符串,因此您可以简单地将其附加到字符串:
serialize()
effectively turns the form values into a valid querystring, as such you can simply append to the string:
$.ajax({
type : 'POST',
url : 'url',
data : $('#form').serialize() + "&par1=1&par2=2&par3=232"
}
这篇关于jQuery:serialize()表单和其他参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文