Load an AJAX submission enabled webform using another AJAX call I am using Javascript/AJAX to call a path defined in a custom module which loads existing node content for display.  i.e. you are at:

/custom/path


and it makes an AJAX request to /custom/content with arguments to load the content for the page (placed in #main-content). Content may be a page, video or other custom Content Types.

Custom navigation elements on the page cause further AJAX requests to /custom/content with different arguments to replace the content.

This has worked well until the need to incorporate webform's into the mix.  Due to the non-refreshing nature of the page the webform needs to be loaded, displayed and submitted using AJAX.

I have setup hook_form_alter to add the necessary $form['actions']['submit']['#ajax'] to webforms and they work properly when called directly.  The form submits via AJAX.  However, when they are loaded via AJAX this does not work.  They submit as per normal and navigate away from my desired wrapper page.

I have ensured Drupal.attachBehaviours is being called post AJAX load.  I suspect my problem is in the loading/rendering of the webform in the module, but have not been able to successfully piece it together.  The module serving /custom/content basically does the following:

$node = node_load($node_id);
$output = drupal_render(node_view($task, 'full', NULL));
echo $output;


It displays the webform perfectly (like other content) - it just doesn't implement the #ajax submission part.  I've tried all manner of more specific form buulding for when $node-type = webform but no success.
Try to create ajax links with this module Ajaxify Drupal with JQuery Ajax.

It will load all ajax behaviour of loaded content(if loaded content contains ajax enabled form then that also)


  Ajax links API module help you to load any content to a specified DIV or ajaxify whole drupal site, using JQuery Ajax. This module will also load JS for Ajax-loaded content by using Drupal.attachBehaviors(). In case you dont want to load js or css, you can alter tpl for path/node type.