【发布时间】:2020-01-25 12:01:55
【问题描述】:
我有一个主表单和多个相关的内联表单。提交主表单时,应同时提交所有其他内联表单。
但是,如果任何内联表单失败(我们在响应中对其进行标记),则不会汇总主表单。
问题是submitInlineForm 返回了一个承诺。如何传递表单提交是否成功,以便在submitForm处理?
let submitForm = $form => {
let formsToSubmit = [];
$('.form-inline').each(function () {
const $f= $(this);
if (submittable($f)) formsToSubmit.push(submitInlineForm($f));
});
$.when(formsToSubmit).done(() => {
if (!allFormsSuccessfull) return false; // how to determine all forms were successfull?
$.ajax({...});
})
};
let submitInlineForm = $form => {
return $.ajax({
url: $form.attr('action'),
type: 'post',
success: response => {
if (response.success) {
// ???????
// what to do here to indicate the inline form was successfully submitted?
} else {
// ???????
}
}
});
};
【问题讨论】:
标签: javascript jquery ajax promise