Sunday, November 28, 2010

Re: RequestHandler::isAjax() buggy?

The function is extremely simple:

function isAjax() {
return env('HTTP_X_REQUESTED_WITH') === "XMLHttpRequest";
}

That's the standard way of checking for an ajax request. In regards
to debugging I'd suggest throwing in some logs, both $_SERVER and when
a successful ajax was accomplished. Track down the timestamp and
cross reference what request is coming across as ajax when it
shouldn't.

Hope that helps,
Nick

On Nov 28, 12:56 pm, cricket <zijn.digi...@gmail.com> wrote:
> I'm seeing some strange behavior on a site. I haven't been able to
> reproduce it locally, just on the server, and it's also only showing
> up just once in a while. What's happening is, occasionally, isAjax()
> is incorrectly returning true, and so just the element is rendered.
>
> public function index()
> {
>         $this->Session->write('path_back', $this->here);
>
>         $this->set('data', $this->paginate());
>
>         if ($this->RequestHandler->isAjax())
>         {
>                 $this->viewPath = 'elements'.DS.'books';
>                 $this->render('pagination');
>         }
>
> }
>
> So, I've got  a paginated list of books, and I'm loading further pages
> using AJAX. The session business allows me to get back to the correct
> index page from a "view" view. I can't think of any reason why that
> would be involved, though.
>
> I can't remember seeing anyone else report this sort of thing. Has
> anyone run into it? Or have any suggestions for why this might be
> occurring? Or how to go about debugging this?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: