dongxian0421
dongxian0421
2015-04-21 09:30

在获取内容之前,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 duanraa1984 6年前

    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();
    }
    
    点赞 评论 复制链接分享
  • dsvf46980 dsvf46980 6年前

    Hi try use a function :

    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');
                }
            });
        });
    }
    
    点赞 评论 复制链接分享

为你推荐