gpt4 book ai didi

ajax - 检查请求是否由 Ajax 发送

转载 作者:行者123 更新时间:2023-12-04 01:17:58 24 4
gpt4 key购买 nike

我正在覆盖一个 magento Controller ,在处理之前,有没有办法知道请求是否由 Ajax 发送?

谢谢

最佳答案

Magento 使用类 Zend_Controller_Request_Http为它的要求。

你可以使用

if ($this->getRequest()->isXmlHttpRequest()) {
// is Ajax request
}

以这种方式检测 Ajax 请求。

至少
  • 样机
  • Scriptaculous
  • jQuery
  • YUI
  • MochiKit

  • 发送 HTTP_X_REQUESTED_WITH标题,根据 ZF docs .

    但请注意,“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;
    }

    根据您对“Ajax”的个人看法,这可能(也可能不)更适合您的需求。

    关于ajax - 检查请求是否由 Ajax 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10911862/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com