Drupal 7 skip loading the template for ajax requests I am trying to upload an image in my template page, using jquery ajax-form submit.

And i am returning just the image name after it is uploaded in the module function.
However, i am getting the entire html as response.

In my theme's template.php, i have used the following code:

function my_theme_preprocess_page(&amp;$vars) { 
  if ( isset($_GET['ajax']) &amp;&amp; $_GET['ajax'] == 1 ) {
        $vars['template_file'] = 'page-ajax';
  }
}


I have this code in my theme's page-ajax.tpl.php: &lt;?php print $content; ?&gt;

And i am passing the 'ajax=1' parameter to the module hook menu function that handles the image upload.
How can i just output the image name in ajax response, instead of the entire html.tpl.php?
How are you generating the ajax response?

If you simply want to return a string eg a file name you can just return it as plain text or as JSON using hook_menu and a callback function eg:

function mymodule_menu() {
    $items['my/custom/path'] = array(
      'page callback' =&gt; 'mymodule_callback',
    );
    return $items;
}
function mymodule_callback() {
  //Do stuff like get filename from DB.
  print 'filename.jpg';

  //to return JSON use drupal_json
  //drupal_json(array('filename' =&gt; 'filename.jpg'))
}