Fortuna
Fortuna

Reputation: 609

jQuery load() path of CakePHP elements()

I try to load elements from CakePHP ($this->elements()) with the jQuery function .load() but I have prolems figuring out the paths to those elements. I found some other topics here on this site, but they didnt help me really.

The root is /webroot isn't it? I tried then .load('../View/Elements/Summoners/comments.ctp'); and some other paths but they didn't work out :/

Upvotes: 0

Views: 2429

Answers (2)

despina
despina

Reputation: 437

The code above doesn't work:

.load(/controller/ajax_action/);

should be:

.load('/controller/ajax_action/');

...and

public function ajax_action() {
$this->renderElement('/elements/element_name.ctp');}

should be...

public function ajax_action() {
$this->render('/elements/element_name');}

Upvotes: 1

Chuck Burgess
Chuck Burgess

Reputation: 11575

Don't load the element from jQuery, but call a controller method that will load the element. For example. In jQuery call something like:

.load(/controller/ajax_action/);

Then in the controller that corresponds to ajax_action, you can either let it load the view it is calling or load the element like so:

public function ajax_action() {
    $this->renderElement('/elements/element_name.ctp');
}

Upvotes: 3

Related Questions