在获取内容之前,AJAX重新加载页面

时间:2015-04-21 09:30:18

标签: javascript php jquery ajax fullpage.js

我正在使用FullPage.js插件,我正在尝试使用AJAX在页面之间进行导航。

当我使用.load();我正在捕捉我需要的页面,但是,正如我现在看到的,我需要重新加载fullpage.js,因为加载的页面不活动,脚本无法使用它。

这是我的代码:

$('.click a').click(function(event) {
            event.preventDefault();

            $.ajax(this.href, {

                cache: false,
                success: function(data) {
                    $('#fullpage').html($(data).find('#fullpage > *'));

                    location.search = "reloaded=1";
                    console.log('The page has been successfully loaded');
                },
                error: function() {
                    console.log('An error occurred');
                }
            });
        });

我如何刷新插件,或者我可以在使用AJAX获取其内容之前加载页面?

也许我可以加载已装载AJAX的页面?

2 个答案:

答案 0 :(得分:2)

如果您正在动态创建部分或幻灯片,则需要再次销毁和初始化fullPage.js。 为此,您需要使用fullPage.js的destroy('all')函数,然后再次初始化它。

类似的东西:

//initializing fullpage.js for the 1st time.
initFullpage();

function myFunction() {
    $('.click a').click(function (event) {
        event.preventDefault();

        $.ajax(this.href, {

            cache: false,
            success: function (data) {
                $('#fullpage').html($(data).find('#fullpage > *'));

                location.search = "reloaded=1";
                console.log('The page has been successfully loaded');

                //destroying fullpage.js completely
                $.fn.fullpage.destroy('all');

                //initializing it again so it can detect new sections.
                initFullpage();
            },
            error: function () {
                console.log('An error occurred');
            }
        });
    });
}

function initFullpage(){
     $('#fullpage').fullpage();
}

答案 1 :(得分:0)

您好尝试使用功能:

function myFunction(){
  $('.click a').click(function(event) {
        event.preventDefault();

        $.ajax(this.href, {

            cache: false,
            success: function(data) {
                $('#fullpage').html($(data).find('#fullpage > *'));

                location.search = "reloaded=1";
                console.log('The page has been successfully loaded');
                myFunction(); // FOR refresh 
            },
            error: function() {
                console.log('An error occurred');
            }
        });
    });
}
相关问题