Sunday, November 28, 2010

Re: RequestHandler::isAjax() buggy?

On Sun, Nov 28, 2010 at 2:56 PM, cricket <zijn.digital@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?


Sorry for the noise. This fell into my lap while I was busily trying
to get something else to deadline and I wasn't thinking things through
very well. It's not a Cake issue, although I'll continue here as it
might be of help to someone someday.

The obvious first step is to log the request headers before rendering
just the element. I did that and see:

[X-Requested-With] => XMLHttpRequest

So Cake is doing the right thing. Next step: check the browser. I was
using FF 3.6.12. I could see that the page is being refreshed but
tried disabling JS anyway. Sure enough, I was able to eventually
repeat it. I then opened the site in Chrome (7.0.517.44) and clicked
away for a while (remember, this bug only shows up occasionally). I
was literally just about to give up on Chrome when the bug showed
itself. I then was able to get Opera (10.10) to do it.

I disabled caching, on the principle that it couldn't hurt, so why
not? No difference.

Speaking of caching: Firefox is showing this un-styled rendered
element, and I try shift-refresh. After four or five tries, the page
finally loads correctly. WTF? This makes no sense at all.

Maybe an Apache bug? That's beginning to seem like the only
explanation. Especially as everything's fine locally. Will update that
and post results.

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: