【问题标题】:AJAX reload page before get contentAJAX 在获取内容之前重新加载页面
【发布时间】:2015-04-21 09:30:18
【问题描述】:

我正在使用 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 的页面?

【问题讨论】:

标签: javascript php jquery ajax fullpage.js


【解决方案1】:

如果您正在动态创建部分或幻灯片,则需要再次销毁并初始化 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();
}

【讨论】:

    【解决方案2】:

    你好尝试使用一个函数:

    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');
                }
            });
        });
    }
    

    【讨论】:

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