How to write "on form submit complete" using javascript?

I have a upload form inside my page, and there is a button from this form, its function is to submit this form.

$('#MyForm').submit();

I want to write a complete submit function, means to know that the form is successfully / fully submitted.

I tried the jquery form plugin but didn't work, I think, because submit comes from a button outside the form.

Does anyone know any different ways?

+3
source share
1 answer

Actually, you can use the jquery form plugin, just use the ajaxSubmit () method.

Documents for the jQuery plugin form.

// setup the form, and handle the success
$('#myFormId').ajaxForm({
  success: function() {
     // do what you are looking to do on 
     // success HERE
  }
});

// setup submission on some random button
$('#someButton').click(function() { 
    // submit the form from a button
    $('#myFormId').ajaxSubmit(); 
});
+6
source

Source: https://habr.com/ru/post/1711597/


All Articles