开发者

Kohana 3 Check if ajax request

I'm currently using this to check if the request is an ajax request:

if ( ! Request::$is_ajax || Request::instance() == $this->request)
{
    exit;
}

If I try to access the page directly it'll exit, but if I make an ajax request, it'll also exit. I also tried just:

if ( ! Request::$is_ajax)
{
    exit;
}

And vice versa, but the script still exits everytime. If I remove the开发者_如何学编程 check, the ajax works as normal. Any idea what could be wrong? Thanks.


  1. When you are using Ajax, Request::instance() === $this->request is TRUE. Use this condition for HMVC calls.
  2. Kohana marks request as Ajax when $_SERVER['HTTP_X_REQUESTED_WITH'] == 'xmlhttprequest' condition is TRUE. Check your client headers (with firebug for example), maybe your JS doesnt send this header. Or, may be you are using flash uploader?


Request::current()->is_ajax() this code works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜