drupal7 - 使用ajax加载节点(jQuery)

问题描述:

我想单击视图中的链接时在节点上动态加载简单内容。有没有办法做到这一点,而不涉及形式?drupal7 - 使用ajax加载节点(jQuery)

+0

没有窗体是的,但你必须为此创建模块 – drupality

对于任何人在未来阅读本 - 从Drupal forums

(function($) { 
    $(document).ready(function() { 
     var selector = '#main-menu li a'; // Or whatever selector you need 
     $(selector).click(function(e) { 
      e.preventDefault(); 
      $.ajax({ 
       url: $(this).attr('href') + '?ajaxrequest', 
       success: function(data) { 
        // I'm assuming here that the wrapper around your content region 
        // will be given an ID of 'region-content', you'll need to check that 
        $('#region-content').replaceWith(data); 
       } 
      }); 
     }); 
    }); 
})(jQuery); 

和模块中:

<?php 
function mymodule_page_alter(&$page) { 
    if (isset($_GET['ajaxrequest'])) { 
     echo render($page['content']); 
     drupal_exit(); 
    } 
} 
?> 

为我工作有一些调整。