使用ajaxSubmit / jQuery提交多个表单时出现问题

时间:2010-11-15 08:40:22

标签: javascript ajax jquery

我有一些代码可以一次在我的页面上提交多个表单:

$('.photo-edit-form form').ajaxSubmit({
     success: function() { console.log('success'); },
     error: function() { console.log('error'); }
});

然而,无论我有多少种形式,我都只获得一次成功打印。我发现我可以通过在所选表单上使用.each来修复它:

$('.photo-edit-form form').each(function() {
     $(this).ajaxSubmit({
          success: function() { console.log('success'); },
          error: function() { console.log('error'); }
     });
});

这是ajaxForm插件的问题还是我对jQuery如何工作的误解?任何意见都将不胜感激。

2 个答案:

答案 0 :(得分:1)

插件的代码行为就像它一次处理任何数字一样,但是it basically comes down to this

$.ajax(options);

data in that option set comes from .formToArray() which only deals with the first element in the set

var form = this[0];

因此,对于您的问题,是,这是插件的问题.ajaxSubmit()一次仅适用于一个<form>,它没有内部.each()就像大多数插件一样。

答案 1 :(得分:0)

据我所知,ajaxSubmit不处理选择器的每个结果。