FormData
can be very convenient (
https://developer.mozilla.org/en-US/docs/Web/API/FormData[
^]), but in fact, with Ajax, it is absolutely not needed. Moreover, the form itself is needed. In fact, the
<form>
element is only mandatory when it is used with the "Submit" button, which automatically sends all key-value pairs in HTTP request, depending on the attribute values of the attribute "
name
" and the values of all controls inside the
<form>
element.
Even though you can use it all with Ajax and
FormData
, this is totally irrelevant to Ajax. You can directly get all name-value pairs from control, in particular, from jQuery wrappers of the control elements, using jQuery
.val()
:
http://api.jquery.com/val[
^].
And the
name
part of the name-value pair could anything, based on attributes
name
or not. It does not matter where you get the controls, are they in some form or not. All you need is to have them all on the page. You can obtain the jQuery wrapper using its
selectors:
http://api.jquery.com/category/selectors[
^],
in particular,
http://api.jquery.com/id-selector/[
^].
—SA