jQuery回调数据没有按顺序加载

时间:2013-07-06 00:57:23

标签: javascript jquery

我有一个网站动态加载window.location.hash更改事件的内容,我有一个非常恼人的问题,我似乎无法修复。在一个身体div内基本上有2个div; id为' loader-container'另一个是$ mainContent所以

<body>
   <div id=loader-container></div>
   <div $mainContent></div>
</body>

在$ mainContent中加载新页面的时候,我希望在loading-container&#39;中显示一个旋转加载gif。问题是我无法让加载器容器加载内容但是$ mainContent的数据确实加载了。这是js:

$(window).bind('hashchange', function(){
    alert("This is being called");
    $('#loader-container').load('loading.php'); //this works here

    newHash = window.location.hash.substring(1);

    if (newHash.substring(1,26) == "content/event.php?event_id"){

        $('#loader-container').load('loading.php'); //this doesnt work but the below code is being called inside the if statement

        $mainContent.slideUp("slow", function() {
            alert("This isnt being called!");
            alert("Below, loading.php isn't being loaded but newHash is");
            $('#loader-container').load('loading.php', function(){
                $mainContent.load(newHash, function() {         //this load's newHash successfully
                    $mainContent.show('slow', function() {
                        $pageWrap.animate({
                            height: baseHeight + $mainContent.height() + "px"
                        });
                        alert("this isn't being called");
                    });
                    alert("or this");
                });
                alert("or this");
            });
            $("#loader-container").hide();
        });
    }
});

0 个答案:

没有答案