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.
- When you are using Ajax,
Request::instance() === $this->request
is TRUE. Use this condition for HMVC calls. - 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.
精彩评论