javascript – 如何单独提交附加表格

标有NEWFORM的按钮可在单击时创建新表单.每个表单都有一个提交按钮.单击每个表单的提交按钮时,该表单的值将通过AJAX发送.我的代码第一次运行良好,但是当创建并提交新表单时,所有表单的所有值都将一起发送.

这是我的片段:

$(document).ready(function() {
  $(".newform").click(function() {
    $(".MyForm")
    .eq(0)
    .clone()
    .show()
    .insertAfter(".MyForm:last");
  });

  $(document).on('click','.MyForm button[type=submit]',function(e) {
    e.preventDefault() // To make sure the form is not submitted 
    $('.MyForm').each(function() {
     console.log($(this).serialize())
      $.ajax(
        $(this).attr('action'),{
          method: $(this).attr('method'),data: $(this).serialize()
        }
      )
    });
  });
});