AJAX 与表单提交 [英] AJAX vs Form Submission

查看:42
本文介绍了AJAX 与表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们从服务器提取数据,如果我们使用 Struts,那么我们可以通过提交一个 MVC 架构 的页面来提取,或者我们可以进行 AJAX 调用但是约定是使用表单和渲染响应,但我们也面临着提供丰富用户体验的挑战,所以我们妥协了约定并开始使用过多的AJAX,那么我们应该如何在两者之间取得平衡?

We pull data from server and for that If we are using Struts, then we can pull either by submitting a page which MVC Architecture or we cam make an AJAX call but conventions is of using forms and render response but we also face challenges to give rich user experience, so we compromise convention and start using excessive AJAX, so how we should make balance between two?

推荐答案

我个人认为 AJAX 应该用于显示更新和表单提交应该通过页面重新加载来完成.推理?

I personally think that AJAX should be used for displays updates and form submissions should be done via a page reload. Reasoning?

提交表单时,您是在告诉应用程序执行某些操作.用户往往想要感觉它已经完成.当页面没有重新加载时,用户通常会想知道那行得通吗?".然后他们必须检查以确保他们所做的是正确的.

When submitting forms, you are telling the application to do something. Users tend to want to feel that it was done. When a page doesn't reload, users are often left wondering "Did that work?". Then they have to check to make sure what they did was right.

另一方面,当您显示图表或其他内容时,例如,当用户说显示 2011 年数据......现在是 2012 年数据"时,他们并没有做"某事(创建新实体,发送电子邮件等).所以在这种情况下,AJAX 可以提供一个很好的用户界面.页面重新加载在这里会很烦人.

On the other hand, when you are displaying a chart or something, and the user says to "display 2011 data....now 2012 data" for instance, they aren't "doing" something (creating new entities, sending emails, etc). So AJAX can provide a nice user interface in this case. Page reloads would be annoying here.

总而言之,我认为表单提交应该通过页面重新加载来完成(让用户看到它正在工作),而显示更新应该使用 AJAX(防止烦人的页面重新加载).

In conclusion, I think form submission should be done via page reloads (let the user see it working), whereas display updates should use AJAX (prevent annoying page reloads).

当然,这是一个偏好的东西.我公司的一些应用程序全部使用 AJAX.但这些是最难维护和调试的应用程序.;)

Of course, this is a preference thing. Some of my company's applications use AJAX all over. But those are the applications that are the most difficult to maintain and debug. ;)

这篇关于AJAX 与表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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