我的html中有这个结构
<div id ="slide1">
<form method="post" id="customForm" action="">
//my content - name, email, mypassword, pass2
</form> //i already tried delete this
</div>
<div id ="slide2">
<form method="post" id="customForm1" action=""> //and this, to have only one form obviously this didn't work, because the div of slide1 is already closed.
//my content - other stuff
</form>
</div>
我有这个JS
$(document).ready(function() {
$("#customForm").submit(function() {
$.ajax({
url: "validation1.php",
type: "post",
dataType: "json",
data: {
name: $('#name').val(),
email: $('#email').val(),
myPassword: $('#myPassword').val(),
pass2: $('#pass2').val()
},
success: function(data) {
//stuff
}
问题是。我想将幻灯片的数据分组并发送到validation1.php,但为此我必须有一个唯一的表单。
如果问题不明确,请告诉我。
感谢
答案 0 :(得分:0)
如果我理解正确你说你需要在一个帖子中发送2张幻灯片,但在你的html中,数据存在于2个表单元素中。
您始终可以使用所需的数据构建新表单并提交,然后还要检查页面上表单的使用情况。
var href = '.... where ever you are sending the data .....';
var form = $('<form method="post" action="' + href + '"></form>');
var d1=$('.slide1 some subdata selector');
var d2=$('.slide2 some subdata selector')
$('<input type="hidden" name="data1">').val(d1).appendTo(form);
$('<input type="hidden" name="data2">').val(d2).appendTo(form);
$('body').append(form);
form.submit();
form.detach();