html - AJAX 是否在整个 GET/POST 过程中维护状态?

标签 html ajax http web-applications

今天开始的热烈讨论。

Developer 1: "AJAX is a set of tools, use it where it really helps, not just for the sake of it."

Developer 2: "Its almost 2011, we can build rich desktop like applications in the browser, we should use AJAX everywhere and make a single page application with everything in it an AJAX powered component."

到目前为止我能理解事情。这是我不明白的地方。

Developer 1: "Using AJAX to make a single page app, we will have to write our own code to manage bookmarking and browser back forward buttons"

Developer 2: "No problem, that's easily doable. It's worth it because AJAX solves the problems we had with normal GET/POST, the statelessness. With a one page AJAX app, you can maintain context, you don't need hidden variables, heavy session management as you would when you moved between pages"

Dev 2 正确吗? AJAX 真的解决了“网络”正常工作方式的问题吗?

最佳答案

没有。

首先,网络的运作方式没有问题。它被设计为无状态的,即使使用单页 AJAX 应用程序,Web 仍然是无状态的。

问题在于开发人员如何在无状态的网络环境中管理状态。对于习惯于在桌面应用程序中轻松管理状态的开发人员来说,单页 AJAX 应用程序无疑使管理状态变得更加容易(实际上,它完全回避了问题)。

但请记住,如果您有一个单页 AJAX 应用程序,并且您忘记将状态发送回服务器以进行持久化,那么您就会丢失它......

在我个人看来,单页 AJAX 应用程序还存在代码管理/可读性/可维护性问题,这些问题远远超过了状态管理的好处。我宁愿学习如何在应用程序中正确地从一个页面传递到另一个页面,以解决包含所有代码的单个页面的麻烦。

关于html - AJAX 是否在整个 GET/POST 过程中维护状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3875471/

相关文章:

javascript - div背景图片不改变重新上传

rest - Rest API 应该只返回结构化数据吗?如果我必须获取 html 怎么办?

html - 如何将文本输入与图像按钮对齐?

javascript - 如何解决这个ajax jquery错误?

html - 隐藏粘性标题栏

php - 当我点击下一页时如何停止所有ajax请求

php - 使用 API 将发票过帐到 XERO

java - Java Servlet 中的 HTTP PUT

javascript - 尝试更新 DOM 中的 HTML 表值时出现错误

javascript - 在 Java 中执行 Javascript 获取 html 文件