[英]jQuery load loads previous page if a is clicked
I have this issue with jQuery .load()
: 我有jQuery
.load()
这个问题:
I have a test page called a.php and in there is: 我有一个称为a.php的测试页,其中有:
sleep(5);
So that sleeps for 5 seconds. 这样就睡了5秒钟。 In my jQuery if that page has started to load and you click another link, it loads that page and then shortly after it loads the previous page.
在我的jQuery中,如果该页面已开始加载,然后单击另一个链接,它将加载该页面,然后在加载上一页后不久。
Is there anyway to stop this? 反正有阻止这个的吗?
Code is below: 代码如下:
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();
});
}
});
Try this : 尝试这个 :
$("a").click(function(){ //On click
// <your original code>
// add this at the end of your function
return false;
});
The return false
statement will prevent the browser to follow the href
address of your a
tag. 该
return false
声明将阻止浏览器跟随href
您的地址a
标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.