在AJAX中加载整个页面

时间:2015-06-20 20:26:37

标签: ajax load

目前,我有一个wordpress网站。我想加载网站的整个页面。我的目标是在网站上放置一个页脚播放器,只有在其余页面加载了AJAX时才会有效。

目标是点击例如文章的链接,然后加载包含该文章的网站。由于文章页面的布局与主页不同,因此仅加载一个div是不够的(请参阅http://newtheme.favoritefm.com)。

我试过这个:

$.fn.initLinks = function() {
    $("a",this).click(function() {
        var url = $(this).attr("href");
        // transition to loading phase ...
        // Ajax post parameter tells the site lo load only the content without header/footer
        $.post(href,"ajax=1",function(data) {
            $("#content").html(data).initLinks();
            // transition to normal phase ...
        });
        return false;
    });
};

$(function() {
   $("body").initLinks();
});

没有做任何事情。怎么办?

1 个答案:

答案 0 :(得分:0)

使用完整的jQuery Ajax方法:$.post而不是$.post

所以你的代码应该是这样的:

    $.fn.initLinks = function() {
    $("a", this).click(function() {
        var url = $(this).attr("href");
        // transition to loading phase ...
        // Ajax post parameter tells the site lo load only the content without header/footer
        $.ajax({
            url: url // your href attr..

                success: function(data) {

                $("#content").html($(data).filter('#content').html());

                // This fills in the #content on the current page with the html in #content from
                // the Request page
            },
            error: function() {
                alert('Could not load Data!!');
            }
        });
        return false;
    });
};

$(function() {
    $("body").initLinks();
});