我阅读了一些 AJAX-Form 教程,例如 这个.标签 form 用于 HTML 代码.但是,我认为没有必要.由于我们通过XmlHttpRequest发送HTTP请求,所以发送的数据可以是任何东西,不需要form中的input.
I read some AJAX-Form tutorial like this. The tag form is used in HTML code. However, I believed that it is not necessary. Since we send HTTP request through XmlHttpRequest, the sent data can be anything, not necessary input in form.
那么,有没有理由在 HTML 中为 AJAX 应用程序添加 form 标签?
So, is there any reason to have form tag in HTML for AJAX application?
除了已经讨论过的渐进增强(不要让你的网站需要 JavaScript,直到它真的必须),一个 <form> 和 onsubmit 是可靠捕获 Enter 按键提交所必需的.
Apart from progressive enhancement as already discussed (don't make your site require JavaScript until it really has to), a <form> with onsubmit would be necessary to reliably catch an Enter keypress submission.
(当然,您可以尝试在单独的表单字段上捕获按键,但它很繁琐、脆弱,并且永远不会 100% 重现浏览器在构成表单提交方面的本机行为.)
(Sure, you can try trapping keypresses on separate form fields, but it's fiddly, fragile and will never 100% reproduce the browser's native behaviour over what constitutes a form submission.)
这篇关于AJAX Web 应用程序中是否需要表单标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
NETWORK_ERROR:XMLHttpRequest 异常 101NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 异常 101)
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XmlHttpRequest onprogress 间隔XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 间隔)
如何修改另一个函数接收到的 XMLHttpRequest 响应文How can I modify the XMLHttpRequest responsetext received by another function?(如何修改另一个函数接收到的 XMLHttpRequest 响应文本?)