I recently started to sprinkle some AJAX into the application I am building right now. Since my other controllers in the end pass everything through to an action which applies the basic page layout I wrote one dedicated ajax controller. At first, since I only had little AJAX, I wrote specific actions in this controller. Then I added more and more AJAX things so I soon ended up with an ajax controller full of code fragments which would usually belong to all kinds of modules of my application. So now I changed it all and have only one action in my ajax controller, which might be named "call". This action needs to know the name of a class and the name of a method to be called, then it will execute it.

I did not want to pass this information over the web because I think it is quite relevant for application security (even if ACL is used in each component) so now while building my normal page I also build a list of possible ajax calls which might be fired by the page. Each of these calls is stored in a session, together with a code. Only this code gets transmitted over the web. On each normal page load the session namespace I am using for this gets deleted which makes calls to old things impossible. In a fully AJAX application there would have to be a different approach to deleting old codes from the session because then there wouldn't be "normal page loads". In my case I only have a few page specific ajax elements, so for me this works.

Any thoughts on this approach?

Other notes:
I am not using JSON right now even though it might make sense. Maybe in the next application. Oh, JSON does not implement AJAX communication, it implements JSON communication instead. Or AJAJ? Or AJAJH? Or AAARGH? ;) On the client side I am using the jQuery framework. Others would be fine, too. ZF allows for using whatever we want to use, that's one of the nice things about it.

Paolo Casarini wrote:
Hi,

  how can I use Ajax within a webapp based on the ZF MVC implementation?
Does anybody use the ZF JSON module to implement Ajax communications?

TIA,
  Paolo.

Reply via email to