아약스 요청이 동일하여 중단되거나 다른 경고 조치가 취해질 수 있는지 테스트하고 싶습니다.새로 고침시 동일한 클라이언트 아약스 요청을 피하십시오.
실제로 클라이언트는 몇 가지 양식 요소를 통해 요청을 변경 한 다음 새로 고침 버튼을 누를 수 있습니다.
나는 똑같은 요청을 잡으려고 애써왔다. 타이머 새로 고침 기능을 유지해야합니다.
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var current_request_id = 0;
var currentRequest = null;
var lastSuccessfulRequest = null;
function refreshTable() {
$('#select').html('Loading');
window.clearTimeout(timer);
//MY CATCH FOR DUPLICATE REQUEST NEEDS WORK
if (lastSuccessfulRequest == currentRequest)
{
//currentRequest.abort();
alert('Duplicate query submitted. Please update query before resubmission.');
}
var data = {
"hide_blanks": $("#hide_blanks").prop('checked'),
"hide_disabled": $("#hide_disabled").prop('checked'),
};
json_data = JSON.stringify(data);
current_request_id++;
currentRequest = $.ajax({
url: "/calendar_table",
method: "POST",
data: {'data': json_data},
request_id: current_request_id,
beforeSend : function(){
if(currentRequest != null) {
currentRequest.abort();
}
},
success: function(response) {
if (this.request_id == current_request_id) {
$("#job_table").html(response);
$("#error_panel").hide();
setFixedTableHeader();
}
},
error: function(xhr) {
if (this.request_id == current_request_id) {
$("#error_panel").show().html("Error " + xhr.status + ": " + xhr.statusText + "<br/>" + xhr.responseText.replace(/(?:\r\n|\r|\n)/g, "<br/>"));
}
},
complete: function(response) {
if (this.request_id == current_request_id) {
$("#select").html("Refresh");
window.clearTimeout(timer);
stopRefreshTable();
window.refreshTableTimer = window.setTimeout(refreshTable, 10000);
lastSuccessfulRequest = currentRequest;
}
}
});
}
//TIMER STUFF TO refreshTable()
//THIS SECTION WORKS FINE
var startDate = new Date();
var endDate = new Date();
var timer = new Date();
function startRefreshTable() {
if(!window.refreshTableTimer) {
window.refreshTableTimer = window.setTimeout(refreshTable, 0);
}
}
function stopRefreshTable() {
if(window.refreshTableTimer) {
self.clearTimeout(window.refreshTableTimer);
}
window.refreshTableTimer = null;
}
function resetActive(){
clearTimeout(activityTimeout);
activityTimeout = setTimeout(inActive, 300000);
startRefreshTable();
}
function inActive(){
stopRefreshTable();
}
var activityTimeout = setTimeout(inActive, 300000);
$(document).bind('mousemove click keypress', function(){resetActive()});
</script>
<input type="checkbox" name="hide_disabled" id="hide_disabled" onchange="refreshTable()">Hide disabled task<br>
<br><br>
<button id="select" type="button" onclick="refreshTable();">Refresh</button>
"정확히 일치합니까?"정확하게, 정확히 무엇입니까? 이전 요청? 이전 요청? 다른 것? 그리고 어떤 의미에서 동일합니까? 같은 사용자로부터? 똑같은 매개 변수들? 같은 헤더? 정확한 요구 사항을 명확히하십시오. 당신이 지금하고있는 방식은 순진합니다. $ .ajax는 다른 객체와 "의미"를 비교할 수없는 지연 객체를 반환하며, 요청의 내용에 대해서는 알려주지 않습니다. 이는 콜백을 추가 할 수 있도록 설계되었습니다. 응답을 처리하십시오. 일단 당신이 의미하는 바를 명확히하면 우리는 더 좋은 방법을 찾을 수 있습니다. – ADyson
또한 쪽지 : jQuery의'.bind'는 jQuery 1.7에서'.on' 방법으로 대체되었고 현재는 완전히 사용되지 않습니다. 여전히 새로운 코드를 사용하거나 더 나쁜 이유가있을 수 있습니다. http://api.jquery.com/bind/ – ADyson
분명히 100 줄의 코드를 게시하지 않고도 귀하의 요점을 확인하는 방법이 있습니다. [mcve]를 읽고 따라합니다. – Tomalak