2013-05-22 4 views
0

내가 jQuery를 .load()이 문제가 클릭하면 이전 페이지 :jQuery를로드로드 A가

내가 테스트 페이지라는 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(); 
     }); 
    } 
}); 
+1

가능한 한 [jquery.load()를 취소하는 방법?] (http://stackoverflow.com/questions/2813168/how-to-cancel-a-jquery-load) – hexblot

+0

@hexblot 내가 찾고있는 항목 내 문제에 대한 해결책이 아니고 대안 인 – Krixxix

+0

이 아닙니다. jquery.load가 생성 한 http 요청을 중지하는 것과 관련된 질문입니다. – hexblot

답변

0

이 시도 :

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

    // <your original code> 

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

}); 

return false 문이 a 태그의 href 주소를 따르는 브라우저를 방지 할 수 있습니다.

+0

아니, 그게 어떻게 든 작동하지 않을 것이라고 httph 요청을 멈출 필요가 있지만,로드 밖에서 xhr.abort()를 사용하여 작동하지 않았다 믿습니다. – Krixxix