Best way to structure AJAX for a Zend Framework application

I was thinking about having a service level module AJAX, with controllers and actions that interact with my model. Lightweight, but not very extensible and violating DRY. If I change the logistics of some process, I will have to edit the AJAX controllers and the regular controllers.

Ideally, I would upload exactly the same actions for javascript users and not for javascript. I thought I might check $_POST['ajax']if it is installed, I would load another (json'y) view for the data. I wonder how to do it / a good way to do it (the controller controller plugin I present?), Or if someone can point me to the UP TO DATE tutorial that describes a really good way to create a larger ajax application.

+5
source share
2 answers

In fact, you can use the request object to determine if the request has occurred via ajax, for example:

// from your controller
if($this->getRequest()->isXmlHttpRequest()) {
    // an ajax request, do something special (e.g. render partial view)
} else {
   // render entire view
}

x-requested-with ( , JS ..). . " ajax":

http://framework.zend.com/manual/en/zend.controller.request.html

+5

XmlHttpRequest. Javascript , , , .

AjaxContext, "context", $_POST ['ajax'].

, , . AJAX. , , , .

+1

All Articles