【问题标题】:drupal7 - loading node using ajax(jquery)drupal7 - 使用 ajax(jquery) 加载节点
【发布时间】:2011-09-21 07:06:30
【问题描述】:

我想在单击视图中的链接时在节点上动态加载简单内容。有没有办法在不涉及表格的情况下做到这一点?

【问题讨论】:

  • 没有表单是的,但你必须为此创建模块

标签: jquery ajax drupal view


【解决方案1】:

对于将来阅读此内容的任何人-来自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();
    }
}
?>

对我进行了一些调整。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多