What are differences between XMLHttpRequest and Ht

2019-08-13 19:31发布

问题:

In Zend Framework and other framework such as Symfony, there is a method named isXMLHttpRequest() to determine this is XMLHttpRequest or not. I wonder that how can framework or PHP distinguish between XmlHttpRequest and HttpRequest?

if($this->_request->isXmlHttpRequest())
{
   //code here
}

回答1:

From the documentation:

Zend_Controller_Request_Http has a rudimentary 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.