一起序列化多个表格? [英] Serialize multiple forms together?
问题描述
您可以将多个表单序列化为一个表单,以便仅发出一个post或ajax请求吗?我已经搜索过了,全部都是通过post/ajax明显地提交每个表单.
Can you serialize multiple forms into one so that only one post or ajax request is made? I have searched around and it is all for submiting each form separently via post/ajax.
推荐答案
使用jQuery serialize()
函数时,它只是将表单转换为格式为a=1&b=2&c=3
的字符串.因此,您当然可以将此函数应用于两种形式,并将结果连接起来,并在它们之间使用&
,然后在ajax调用中使用结果.您希望进行一些检查,以确保在进行串联时,两个字符串都不为空.
When you use the jQuery serialize()
function, it simply turns your form into a string in the format a=1&b=2&c=3
. So you can certainly apply this function to two forms and concatenate the result, with an &
between them, and use the result in your ajax call. You'd want some checks to make sure neither string is empty when you do the concatenation.
这篇关于一起序列化多个表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!