Ajax 请求是否通过 MVC 框架(例如 ColdBox)?

发布于 2024-07-29 02:05:41 字数 353 浏览 9 评论 0原文

您是通过选择的 MVC 框架还是直接向 CFC 发出 ajax 请求?

我倾向于绕过 MVC,因为我不需要 ajax 请求中的“视图”。

通过 MVC 框架(如 Coldbox)路由 ajax 调用有哪些优点?

更新:找到此页面 http://ortus.svnrepository.com/coldbox/trac .cgi/wiki/cbAjaxHints 但我仍在尝试思考它带来的好处相对于它引入的复杂性......

Do you fire ajax requests through the MVC framework of choice, or directly to the CFC?

I'm leaning towards bypassing the MVC, since I need no 'View' from the ajax request.

What are the pro's of routing ajax calls through MVC framework, like Coldbox?

update: found this page http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbAjaxHints but I am still trying the wrap my mind around what benefits it brings over the complexity it introduces...

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

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

发布评论

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

评论(6

请爱~陌生人 2024-08-05 02:05:41

Henry,我向代理模型的对象发出 Ajax 请求。 通常,我这样做时是在“框架”之外的。 话虽如此,利用您的框架可能(非常)有必要,例如在设定的安全模型内工作。

Henry, I make my Ajax requests to proxy objects of my model. Typically, I am outside of a 'framework' when doing so. That being said, it may be (very) necessary to utilize your framework, such as working within a set security model.

回心转意 2024-08-05 02:05:41

我确实看不出绕过 MVC 框架有什么好处 - 结合起来,这三个元素就是您的应用程序。

您的 ajax 元素实际上是视图的一部分。 正如 Luca 所说,视图输出模型和控制器的结果。

这样看——如果你制作了一个 iPhone 友好的 Web 界面(即一个新的视图),你会绕过模型和控制器吗?

I can't really see any benefit of bypassing the MVC framework - in combination, those three elements are your application.

Your ajax elements are really part of the view. As Luca says, the view outputs the results of the model and controller.

Look at it this way - if you made an iPhone-friendly web interface (that is, a new View), would you bypass the model and controller?

奢欲 2024-08-05 02:05:41

Luis Majano,ColdBox 的创建者 说:

这是ajax的两个流派
互动亨利。

我更喜欢代理方法,因为它
添加以下内容:

  1. 调试
  2. 在调试器中进行跟踪
  3. AOP拦截点
  4. 安全
  5. 设置可用性
  6. 代理将中继到事件模型,因此我可以使用本地拦截
    点、本地AOP、插件等

换句话说,它可以是一个高度
受监控的呼叫而不是简单的
服务 cfc 调用,您仍然可以
做。

就我而言,我喜欢被处决
正在运行的探查器(冷箱的一部分
调试器),这样我就可以看到ajax
请求的到来以及请求何时到来
出去。 我可以看到请求的数据并且
发回的数据。 我不必
查看日志文件,或者尝试想象
结果或问题。 这确实有帮助
正在调试中。

但是,这将是一个开发人员
选择您决定走哪条路。
我个人的偏好是始终
使用我的代理进行事件委托
因为它给了我更多
灵活性、调试和平和
介意。

Luis Majano, creator of ColdBox said:

These are the two schools of ajax
interaction henry.

I prefer the proxy approach because it
adds the following:

  1. Debugging
  2. Tracing in the debugger
  3. AOP interception points
  4. Security
  5. Setting availability
  6. The proxy will relay to the event model, so I can use local interception
    points, local AOP, plugins, etc.

In other words, it can be a highly
monitored call instead of a simple
service cfc call, which you can still
do.

I, for one, love to have my execution
profiler running (part of the coldbox
debugger), so I can see when ajax
requests come in and when they come
out. I can see the data requested and
the data sent back. I don't have to
look in log files, or try to imagine
results or problems. It really helps
out in debugging.

However, it would be a developer
choice in which way you decide to go.
My personal preference is to always
use my proxy to event delegation
because it gives me much more
flexibility, debugging and peace of
mind.

各空 2024-08-05 02:05:41

MVC 框架中“视图”的目的是在“模型”和“控制器”生成数据后显示数据。 如果不需要“视图”,那么使用这样的设计模式有什么意义呢?

The purpose of the "view" in MVC frameworks is to show the data after the "model" and "controller" have generated it. If you don't need the "view", then what's the point of using such a design pattern?

不疑不惑不回忆 2024-08-05 02:05:41

我同意卢卡的观点。 它还绕过 MC 堆栈中的任何类型的清理和过滤逻辑。 它基本上否定了您可能有或没有的任何类型的查询处理。

I agree with Luca. It also bypasses any kind of sanitization and filtering logic you have in your MC stack. It basically negates any kind of query processing that you may or may not have in place.

审判长 2024-08-05 02:05:41

是的,我不会绕过你的框架,找出导致你悲伤的原因并找出有问题的部分,添加逻辑以排除常见组件(例如页眉或页脚),并寻找注入空白的方法,尽管对于 html 来说很好,但很烦人或令人沮丧解析 json 时出现问题。

添加 output="false" 特别是在您的 application.cfc 及其方法中将是我清理的第一件事。

我坚信永远不要直接访问 CFC,我发现当重大重构可能想要合并或消除组件时,它会产生长期问题,直接访问可能会使这变得比应有的困难,特别是如果第三方是从另一个域(例如 flash remoting)访问您的 ajax。

对史蒂夫的回答+1。

Yeah, I wouldn't bypass your framework, figure out what's causing you grief and hunt down the offending pieces, adding logic to exclude common components such as headers or footers, and looking for methods injecting whitespace that while fine for html is annoying or down right problematic when parsing json.

Adding output="false" especially in your application.cfc and it's methods would be the first thing I cleaned up.

I am a strong believer in NEVER directly accessing the CFC's directly, I find it creates long term problems when a major refactor might want to consolidate or eliminate components, the direct accesses potentially make this harder than it should be, especially if a third party is hitting your ajax from another domain(e.g. flash remoting).

+1 to Steve's answer.

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