开发者

drupal7 - loading node using ajax(jquery)

I wanted to load simple content dynamically on a node when a link in a开发者_如何学编程 view is clicked. Is there a way to do that without involving forms?


For anyone reading this in the future - from the 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);

And in the module:

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

Worked for me with a few tweaks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜