jQuery: ajaxSubmit / ajaxForm any significant difference?

ErickBest picture ErickBest · Jul 21, 2013 · Viewed 10k times · Source

Somehow ajaxSubmit and ajaxForm kinda play the same role. If so, then, Is there any significant difference between them ? If so; which to use, when and why?

Answer

Jason picture Jason · Jul 21, 2013

The FAQ reads:

What is the difference between ajaxForm and ajaxSubmit?

There are two main differences between these methods:

  • ajaxSubmit submits the form, ajaxForm does not. When you invoke ajaxSubmit it immediately serializes the form data and sends it to the server. When you invoke ajaxForm it adds the necessary event listeners to the form so that it can detect when the form is submitted by the user. When this occurs ajaxSubmit is called for you.
  • When using ajaxForm the submitted data will include the name and value of the submitting element (or its click coordinates if the submitting element is an image).

So, ajaxSubmit actually submits the form to its destination while ajaxForm preps everything and waits for the form to be submitted.

Your could run ajaxSubmit in place of $("#formID").submit()


UPDATE

In response to the comment below about uploadProgress the Options page on the same site says:

Note: Aside from the options listed below, you can also pass any of the standard $.ajax options to ajaxForm and ajaxSubmit.

Both ajaxForm and ajaxSubmit support numerous options which can be provided using an Options Object.

There is nothing on uploadProgress being excluded from either so I would say uploadProgress is available in both. How that's used is a different question altogether ;-)