AJAX Web 应用程序中是否需要表单标签? [英] Is Form Tag Necessary in AJAX Web Application?

查看:18
本文介绍了AJAX Web 应用程序中是否需要表单标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了一些 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 应用程序中是否需要表单标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆