[英]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.