Do I still need a Form element when using a AJAX request?

后端 未结 2 590
滥情空心
滥情空心 2021-01-06 11:02

This might be a silly question but it is really matter to me to know if we really STILL need to wrap our input elements in side a

even when we are
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-06 11:24

    When using Ajax, the form serves several purposes. It provides:

    • a way for the user to submit the data to the server when the JavaScript fails for any reason
    • a convenient DOM interface to the controls inside it (formElement.elements.field_id_or_name)
    • a semantic grouping that is (for example) used by screen reader software
    • handling for the pressing of the enter key to trigger the submit event across all the fields

    You don't strictly need it unless you want a robust, accessible, usable page without much more effort.

提交回复
热议问题