0
votes

So here is the situation: I have my default.ctp and my ajax.ctp where my ajax.ctp is just the blank $content_for_layout;

When i'm doing an autocomplete ajax call I must change the layout to 'ajax' obviously. So I have this function in my controller

function beforeFilter() {
        if($this->RequestHandler->isAjax()) {
            $this->layout = 'ajax';
        }
    }

However when i look at the results of my autocomplete I get this in my options:

  • DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
  • html xmlns="http://www.w3.org/1999/xhtml">

Which basicly is my default layout. So my guess is that the layout didn't change

Anyone else encountered this problem? Did I forget to add something in my controller ? All the helpers and components are in place.

1
Problem solved, my movie_autocomplete.ctp had a capital in the name so he was searching for movie_auto_complete.ctp which didn't exist. I felt silly when discovering that...Christophe

1 Answers

0
votes

There isn't that much that could go wrong in your script. Before filter is good and setting the view template is also. The only thing I can think of is that your ajax request somehow doesn't get recognized.

The code of RequestHandler::isAjax() is pretty simple:

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

So I suggest logging your vars to see if it's recognized as ajax. Also I heard sometimes the caching screws this up. Try $this->disableCache(); before checking if it's ajax.

Debugging ... isn't it fun