'Do AJAX operations need the action and post attributes in <form> the way an HTML post submissions does?

I understand how the action and method attributes work when submitting a form, but is it needed in AJAX operations?

Basically looking for the difference between using AJAX to submit a form to a server versus using HTML post.



Solution 1:[1]

AJAX doesn't need a form at all, it is a way of sending a request from the browser to the server which can contain any data you want. For instance, you can track where the user moves their mouse, and send this data to your server every few milliseconds.

If you are using it to send the contents of a form, then technically no, you don't need action and method attributes, because you can read the form fields directly, and send them wherever you like. However, it's usually a good idea to have them anyway, if only as a fallback for if the JavaScript goes wrong, or the user has JavaScript switched off.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IMSoP