I have a drupal site.

There is a page (page 1) with a form that gathers user info and submits it via AJAX to a Drupal Module page.

The AJAX format is jquery

var responseTarget = '/site/module/page_name';
  jQuery.post(responseTarget, {
      key1: value1, key2: value2,.......
  }, function(responseText, statusText, xhr) { 
    if (xhr.status === 200) {  

The module page has the URL format "site/module/page_name" (page 2) and is constructed from the module file "page_name.tpl.php".

This (page 2) processes the user information and sends it to an external server.

The server replies to my (page 2) which processes the response by saving a value to the user account.

The (page 2) then responds to the AJAX call on (page 1).

When my AJAX receives the response it is the response from Drupal (page 2), not from the external server.

  • responseText = the whole Drupal page2, as it is part of a module it contains the header and footer and the processed php of the page as HTML, no objects or values.
  • xhr.status = 200 // Drupal page2 success

What I would like to do is read the response from the server in my page 2 and pass this pack to the AJAX script, or process the value returned from the server in page 2 and pass a status/value/... back to the AJAX script based on this.

I have tried getting Drupal page 2 to echo a JSON object but this is done within the module and Drupal prints it out as part of the page HTML.


[page 1 (ajax)] --> [page 2 (Drupal module)] --> [External Server]

[External Server (modifies an object)] --> [page 2 (processes the object and incorporates it into a full Drupal page, and removes whatever header, status was sent from external server] --> [page 1 (ajax) receives the status and data from page 2]

1 Answer 1


Try this:

$commands[] = ctools_ajax_command_redirect('node/1');
print ajax_render($commands);

Reference D7 AJAX Form Redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.