Jür*_*len 32
Magento将该类Zend_Controller_Request_Http用于其请求.
您可以使用
if ($this->getRequest()->isXmlHttpRequest()) {
// is Ajax request
}
Run Code Online (Sandbox Code Playgroud)
以这种方式检测Ajax请求.
至少
HTTP_X_REQUESTED_WITH根据ZF文档发送标题.
但请注意,"Ajax请求"是指使用XmlHttpRequest发送的请求(而不是使用隐藏的<iframe>s或Flash上传等技术).
由于这是主观的,你的感知可能会有所不同:Magento本身似乎比我更加扩展地定义了"Ajax".看看Mage_Core_Controller_Request_Http::isAjax():
public function isAjax()
{
if ($this->isXmlHttpRequest()) {
return true;
}
if ($this->getParam('ajax') || $this->getParam('isAjax')) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
根据您对"Ajax"的个人看法,这可能(或可能不)更符合您的需求.
Dmi*_*sev 10
如果我没有弄错,magento是使用Zend Framework编写的,因此可以使用Request对象
if($this->getRequest()->isXmlHttpRequest()){
// ajax
} else {
// not ajax
}
Run Code Online (Sandbox Code Playgroud)
http://framework.zend.com/manual/en/zend.controller.request.html#zend.controller.request.http.ajax
祝好运!:)
你可以使用这个:
if ($this->getRequest()->getParam('ajax')){
//Ajax related code
} else {
//Non ajax
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18129 次 |
| 最近记录: |