Monday 25 February 2013

Detecting AJAX Requests in Zend Framework 1


In Zend Framework 1, the Zend Controller Request Object (Zend_Controller_Request_Http) has a method for detecting AJAX requests: isXmlHttpRequest().

This method looks for an HTTP request header X-Requested-With with the value 'XMLHttpRequest'; if found, it returns TRUE. otherwise it return FALSE.

In any controller action, if you need to check whether the HTTP Request as 'AJAX', here is the code

<?php

class UserController extends Zend_Controller_Action {
  public function loaddataAction(){
   if($this->_request->isXmlHttpRequest()){
    //ajax call request
   }
  }
}

?>
Hope you enjoyed this Post.

No comments:

Post a Comment