开发者

Module only to process Ajax requests

开发者 https://www.devze.com 2023-04-04 01:07 出处:网络
I am creating an application that will make heavy use of Ajax and performance is required. I\'ve searched the best ways to handle Ajax requests using the Zend开发者_如何学C Framework, and saw that the

I am creating an application that will make heavy use of Ajax and performance is required. I've searched the best ways to handle Ajax requests using the Zend开发者_如何学C Framework, and saw that the most commonly used ways are the Context-switch and/or an Action per Controler to handle Ajax requests. If I were to use the first way I would have to keep a script in the view for each type of format that I could return (JSON, XML, etc.), and I think it's unnecessary, and the second way, I would get an action full of if/elses.

I do not see anyone suggesting the creation of a module only for Ajax, this would be a bad practice? In my opinion this would make things easier, and the whole code for Ajax would be in one place, I would like to know what you think about it before making a decision, and of course, constructive criticism is welcome.


If you have a controller which only needs to handle AJAX, then you can just use the views as usual. The context switch is meant for cases where an action needs to serve multiple types of contents (JSON, XML, HTML etc.).

If you know that the whole controller will just output JSON, for example, you can create a single view (or no view at all) and call this particular view from all actions in the controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号