dongxian0421 2015-04-21 09:30
浏览 64
已采纳

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

I am using FullPage.js plugin, i am trying to make navigation between pages with AJAX.

When i am using .load(); i am catching page i need, but, as i see now i need to reload fullpage.js, because loaded page isnt active, script doesnt work with it.

Here is my code:

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

How can i refresh plugin, or can i load page before i get its content with AJAX?

Maybe i can load page with AJAX already been loaded?

  • 写回答

2条回答 默认 最新

  • duanraa1984 2015-04-21 09:45
    关注

    If you are creating sections or slides on the fly, then you would need to destroy and initialize fullPage.js again. To do so, you would need to use the destroy('all') function of fullPage.js and then initialize it again.

    Something like:

    //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条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭