How to get full content including template HTML

Here’s how to check if the current page is being loaded via an AJAX request, use this to exit from the header/footer/whichever parts

/* AJAX check  */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  return; // it's an ajax request ABORT!!
}