Generally in AJAX request no need of load CSS, JS. Also omitting other HTML code.
Make ajax.ctp file in /src/Template/Layout, and code should be
<?php
$this->fetch('content');
Set AJAX based layout for entire application, in AppsController.php
class AppsController extends Controller {
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
if($this->request->isAjax())
{
$this->viewBuilder()->layout('ajax'); // For Version >= 3.1 or
$this->layout = 'ajax'; // for version < 3.1
}
else
{
$this->viewBuilder()->layout('admin'); // For Version >= 3.1 or
$this->layout = 'admin'; // for version < 3.1
}
// your other code should be here
}
}