Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a form loading inside my page and there is a button out side this form its function is to submit this form.

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

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

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

anyone knows any different ways?

like image 805
Amr Elgarhy Avatar asked May 22 '26 23:05

Amr Elgarhy


1 Answers

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

Documentation for the jQuery form plugin.

// 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(); 
});
like image 128
cgp Avatar answered May 25 '26 13:05

cgp