如何判断是否在Kohana 3中使用AJAX进行了请求?

时间:2022-10-13 15:09:34

I've tried these

我试过这些

request::is_ajax()

Request::instance()->is_ajax

To no avail. I've noticed in the request class there is a public property $is_ajax but I can't seem to be able to access the property.

无济于事。我已经注意到在请求类中有一个公共属性$ is_ajax但我似乎无法访问该属性。

What am I doing wrong?

我究竟做错了什么?

3 个解决方案

#1


5  

You could also use this:

你也可以用这个:

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

That way you know that it's an ajax- or ajax-like-request

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

I use this in my controller base-class so I know whether or not to render the full or partial view.

我在我的控制器基类中使用它,所以我知道是否呈现完整或部分视图。

#2


9  

in case anyone comes back to this, in Kohana 3.1 it is now $this->request->is_ajax() if you are in a controller.

万一有人回到这里,在Kohana 3.1中现在是$ this-> request-> is_ajax()如果你在控制器中。

#3


3  

I ended up getting it to work with Request::$is_ajax

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

Seems they've gotten rid of the function, and are now relying on a public property.

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

#1


5  

You could also use this:

你也可以用这个:

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

That way you know that it's an ajax- or ajax-like-request

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

I use this in my controller base-class so I know whether or not to render the full or partial view.

我在我的控制器基类中使用它,所以我知道是否呈现完整或部分视图。

#2


9  

in case anyone comes back to this, in Kohana 3.1 it is now $this->request->is_ajax() if you are in a controller.

万一有人回到这里,在Kohana 3.1中现在是$ this-> request-> is_ajax()如果你在控制器中。

#3


3  

I ended up getting it to work with Request::$is_ajax

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

Seems they've gotten rid of the function, and are now relying on a public property.

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