2013-06-08 5 views
1

jquery를 사용하여 외부 페이지를로드하고 View라는 DIV에 표시합니다.Jquery Stop로드 및 지우기 간격

2 개의 버튼이 있습니다. & 그만합니다.

이 방법이 효과적이지만 중지를 클릭하면 몇 초가 걸릴 수 있습니다. 즉시 중지 할 수있는 방법은 없나요?

$("#Go").click(function() { 
    $("#view").load("test.php"); 
    refreshId = setInterval(function() { 
    $("#view").load("test.php"); }, 1000); 
}); 


$("#Stop").click(function() { 
    clearInterval(refreshId); $("#view").stop(); 
    $.ajax({ url : 'new.php' }); 
} }); 

감사합니다 :)

답변

0

당신이 시도 할 수 있습니다 :

var xhr = $.ajax({ 
    type: "POST", 
    url: "test.php", 
    data: "name=John&location=Boston", 
    success: function(msg){ 
     $("#view").html(msg); 
    } 
}); 

및 통화 중지 :

//kill the request 
xhr.abort() 
+0

정지가 다른 페이지로 데이터를 전송합니다. – JeffVader