【问题标题】:How can I tell if a request is made with AJAX in Kohana 3?如何判断是否在 Kohana 3 中使用 AJAX 发出请求?
【发布时间】:2010-02-04 03:15:40
【问题描述】:

这些我都试过了

request::is_ajax()

Request::instance()->is_ajax

无济于事。我注意到request 类中有一个公共属性$is_ajax,但我似乎无法访问该属性。

我做错了什么?

【问题讨论】:

  • request::is_ajax() 应该这样做,你能提供更多你调用它的上下文吗?

标签: php ajax xmlhttprequest kohana


【解决方案1】:

如果有人回到这个问题,在 Kohana 3.1 中它现在是 $this->request->is_ajax() 如果你在控制器中。

【讨论】:

    【解决方案2】:

    你也可以这样用:

    if (Request::$is_ajax OR $this->request !== Request::instance())
    { .. }
    

    这样你就知道它是一个 ajax 或类似 ajax 的请求

    我在我的控制器基类中使用它,所以我知道是渲染完整视图还是部分视图。

    【讨论】:

      【解决方案3】:

      我最终让它与Request::$is_ajax一起工作

      似乎他们已经摆脱了该功能,现在依赖于公共财产。

      【讨论】:

        猜你喜欢
        • 2014-12-24
        • 1970-01-01
        • 2021-05-07
        • 1970-01-01
        • 2013-01-15
        • 2019-03-29
        • 2013-02-21
        • 2010-10-15
        • 2023-03-31
        相关资源
        最近更新 更多