0

次のコードでは、ページをリクエストしたときにこのようなエラーが発生し、404 が返されます。代わりに、アラートが表示されるはずです。奇妙なのは、で ajax されたリンクでのみこれを実行し、更新/変更しないリンクでは正常に機能することです。

('.page-wrap').append('<img src="img/graphics/ajax-loader.gif" class="ajax-loader" />');

    var target = $('section.content'),
        siteURL = 'http://' + top.location.host.toString(),
        internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']"),
        links = $('a'),
        URL,
        el,
        mainContent,
        headContent,
        headClasses,
        pageName,
        ajaxSpinner = $('.ajax-loader');
    internalLinks.click(function(e) {

        el = $(this);

        URL = el.attr('href');

        $('.current_page_item').removeClass('current_page_item');
        el.addClass("current_link").parent().addClass("current_page_item");

        ajaxLoader(URL, false);

        e.preventDefault();

    });

    function ajaxLoader(location, isHistory) {
            $("html, body").animate({ scrollTop: "0px" });
            ajaxSpinner.show();
            $('.page-wrap').css('opacity', '0.5}');


            // Load New Page
            $.get(location, function(data) {
                mainContent = $('section.content', data).html();
                headContent = $('.feature-content', data).html();
                pageName = $('.page-name', data).html();
                headClasses = $('header', data).attr('class');
                $('section.content').html(mainContent);
                $('.page-name').html(pageName);
                $('.feature-content').html(headContent);
                if (headClasses) {
                    $('header').attr('class', headClasses);
                } else {
                    $('header').removeClass();
                }
                if (!isHistory) {
                    history.pushState(location, '', location);
                }

                $(resizeHeader);

                ajaxSpinner.fadeOut();
            }).error(function() {
                alert('woops'); // or whatever
            });
    }
    w.bind('popstate', function(event) {
        if (event.originalEvent.state !== null ) {
            ajaxLoader(event.originalEvent.state, true);
        }
    });
4

1 に答える 1