Home javascript What's the difference between $ (form) .submit () and $ (form) .ajaxSubmit...

What’s the difference between $ (form) .submit () and $ (form) .ajaxSubmit () and the difference between success inside submitHandler () and success inside submit ()?




When using the jquery.validate () plugin, a question arose about the submitHandler () method, inside which there could be a $ (form) .submit () and $ (form) .ajaxSubmit () method. Please explain the purpose of these methods and the difference between them. It is clear that they are submitting the form, but why call them when submitHandler () already implies submitting the form. And what’s the difference between success callbacks inside submitHandler () and success inside submit ()?

Answer 1


submitHandler (default: native form submit)

Type: Function ()

Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it is validated

submitHandler (default: native form submit)
a callback function to handle the actual form submission, replaces the standard form submission. Gets the shape as the only item. Correct place to submit form via ajax after validation.

Example: Submitting a form via ajax

$ ("# myform"). validate ({
 submitHandler: function (form) {
  $ (form) .ajaxSubmit (); // or via form.submit ();

$ (form) .submit () and $ (form) .ajaxSubmit (). Please explain the purpose of these methods and the difference between them …

.submit () – jquery function for synchronous form submission like if you just clicked a button on the form button type = "submit" or enter on the form, etc.

.ajaxSubmit () – not a jquery function, intended for asynchronous form submission (via ajax)

In other words, in submitHandler you can do whatever you want before submitting the form and then trigger it to submit.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions