在通用处理程序中处理不同 ajax 调用的最佳实践

发布于 2024-12-21 17:31:59 字数 133 浏览 2 评论 0原文

我在项目中进行了很多 ajax 调用,而我的通用处理程序通常非常混乱。你们对如何在同一文件中管理大量通话有什么建议吗?我当前的解决方案是将函数名称作为第一个参数传递,然后根据名称决定在处理程序中结束的位置。但这感觉不是最好的方法。非常感谢任何提示。谢谢

I do a lot of ajax calls in my project, and my generic handlers usually en up pretty messy. Do you guys have any tips on how to manage a lot of calls in the same file? My current solution is to pass a functionname as the first parameter, and then decide on where to end up in the handler based on the name. But this doesnt feel like the best way. Any tips are much appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拒绝两难 2024-12-28 17:31:59

当您想要获取有关服务器了解的资源的信息、删除资源或放置新状态时,请定义引用该资源的 URI。查询字符串参数可以很好地定义哪一个(例如?id=34),但不能定义资源类型——这会混淆太多单独的问题。

POST 处理程序不应处理太多不同的任务。理想情况下是一个,但如果它们的操作非常,可能会延伸到更多。

换句话说,Ajax 并没有带来什么新东西,在幕后它与我们在 90 年代使用的基于 HTTP 的 Web 相同。 Ajax 只是解决这个问题的一种新方法。

When you want GET information on a resource the server knows about, or to DELETE one, or PUT a new state, then define a URI that refers to it. Querystring parameters are fine for defining just which one (e.g. ?id=34) but not types of resource - that confuses too many separate issues.

POST handlers shouldn't handle too many different tasks. Ideally one, though maybe stretching to a few more if they are very similar in their operation.

In other words, Ajax brings nothing new, behind the scenes it's the same web built on HTTP that we had in the 90s. Ajax is just a new way to deal with that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文