繁体   English   中英

如果单击a,jQuery加载将加载上一页

[英]jQuery load loads previous page if a is clicked

我有jQuery .load()这个问题:

我有一个称为a.php的测试页,其中有:

sleep(5); 

这样就睡了5秒钟。 在我的jQuery中,如果该页面已开始加载,然后单击另一个链接,它将加载该页面,然后在加载上一页后不久。

反正有阻止这个的吗?

代码如下:

jQuery(document).ready(function(){

$("#load").hide(); //Hife the loading bar


$("a").click(function(){ //On click
    if(!$(this).hasClass('ignoreJS'))
    {
        $("#load").show();

        $("#mainContent").hide();

        addActive( this );

        var FullAttribute = $(this).attr('href');
        var FinalAttribute = FullAttribute.slice(1);

        $('#mainContent').load( FinalAttribute + '.php', function(response, status, xhr)
        {
            if(status)
            {
                if(status == 'error' && xhr.status != 0)
                {
                    $('#mainContent').html('<h2 class="errorText">Error ' + xhr.status + ' </h2>');
                }
                waitingToLoad = false;

            }
            $("#mainContent").show();
            $("#load").hide();
        });
    }
});   

尝试这个 :

$("a").click(function(){ //On click

  // <your original code>

  // add this at the end of your function
  return false;

});

return false声明将阻止浏览器跟随href您的地址a标签。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM