vibha
vibha

Reputation: 129

Avoid the display of default layout in AJAX request in CakePHP

I want to show a test div when the event onchange of a select is triggered, but in result div total default layout is displayed. I just want test.ctp to appear in my result div.

This is my code, please tell what is wrong here. I've a dropdown with id="ProductCategoryId" and a result div like:

<div id="result">result html</div>

This is the jQuery function:

$("#ProductCategoryId").change(
  function() {
    var catid = $(this).val();
    $.post('product/test', {id: catid},
    function(result) {
      $('#result').html(result);
    });
  }
);

In my product_controller:

function test() {
  $this->autorender = false;
  $this->layout = 'ajax';
}

and in test.ctp only test output is written.

Upvotes: 1

Views: 5713

Answers (1)

Ehtesham
Ehtesham

Reputation: 2985

I don't know whether you have figured out the problem or not. Well if don't want to wrap layout around your view you can simply set layout to false. And I see you have disabled the auto rendering that means you are specifically calling controller's render('test') function.??

   $this->autorender = false;
   $this->layout = false;
   $this->render('test');

Upvotes: 1

Related Questions