ajax和没有形式,会发生什么? [英] ajax and no forms, what will happen?
问题描述
我注意到我的网站没有一个< form>
,但登录除外。我不知道如何或为何发生,但我发现我使用jquery和ajax发布一切然后刷新(或不,如果我不需要)。如何以及为什么用户会因此而受苦?
I notice my site does not have a single <form>
with the exception of logging in. I am not sure how or why it happened but i found i use jquery and ajax to post everything then refresh (or not if i dont need to). How and why would the user suffer from this?
我的一些'表格'包括
Some of my 'forms' include
- 在页面上留言
- 删除邮件 发送一条私人消息(然后我将document.location = nextPage) / li>
- 标记为最爱。
推荐答案
评论,我看到你不打算支持没有JavaScript的用户,所以可访问性和向后兼容性参数是没有意义的。
From your comment, I see that you don't intend to support users without JavaScript, so the accessibility and backward compatibility argument is moot.
然而,你可能会创建很多通过使用AJAX发布不必要的请求,然后刷新页面。这是不是 AJAX是如何使用的,可能是反模式。 AJAX的思想是发送特定数据并接收特定数据,并根据接收到的数据更新页面,而不是刷新。
However, you are likely creating a lot of unnecessary requests by posting with AJAX and then refreshing the page. This is not how AJAX was intended to be used and is possibly an anti-pattern. The idea of AJAX is to send specific and receive specific data, and to update the page based on that received data, not refreshing.
另外,通过不使用窗体,您可以禁用默认提交功能(按< enter>
)作为< a href =https://stackoverflow.com/questions/2285685/ajax-and-no-forms-what-will-happen/2285748#2285748> Doug Neiner 指出
Also, by not using form's, you disable the default submit functionality (pressing <enter>
) as Doug Neiner pointed out
这篇关于ajax和没有形式,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!