Craig McCoy

Programmer / Developer & Zombie Survivalist

Drupal: Make AJAX Calls To Pages & Module Paths

Mar/2011 18
A really simple and easy way to modify your theme page.tpl file to handle ajax calls is to: 1. Above the first output in the page.tpl file (doctype declaration) Add the following code:
 if(!isSet($_GET["ajax"]) && !isSet($_POST["ajax"])) {
2. At the very end of the page.tpl file, add the following code:
} else {
   print $content;
}
Usage: When you make an AJAX call to a page, or a path that you have in a custom module, just add ajax=true to the url. Example:
<a href="node/43?ajax=true" class="modal">Launch Modal</a>
This way, all that is output is what is in the $content variable.