반응형
jQuery Refresh/Ajax Success가 예상 시간 이후인 경우 페이지 다시 로드
저는 Jquery를 사용하여 Ajax를 요청합니다.서버는 다음과 같이 "true or false" 값을 가진 Json 개체를 반환합니다.
return Json(new { success = false, JsonRequestBehavior.AllowGet });
서버가 true를 반환하면 5초 후에 페이지를 새로 고칠 방법이 있습니까?
Ajax 성공 콜백 시 다음 작업을 수행합니다.
success: function(data){
if(data.success == true){ // if true (1)
setTimeout(function(){// wait for 5 secs(2)
location.reload(); // then reload the page.(3)
}, 5000);
}
}
5초 후에 페이지를 다시 로드하려면 답변에 제시된 대로 타임아웃이 필요합니다.
location.reload();
사용할 수 있습니다.reload당신의 기능을 합니다.if조건이 성공하면 페이지가 다시 로드됩니다.
if(success == true)
{
//For wait 5 seconds
setTimeout(function()
{
location.reload(); //Refresh page
}, 5000);
}
이 방법이 더 좋습니다.ajaxStop+setInterval,, 이것은 같은 페이지에서 XHR[ajax] 요청 후에 페이지를 새로 고칩니다.
$(document).ajaxStop(function() {
setInterval(function() {
location.reload();
}, 3000);
});
var val = $.parseJSON(data);
if(val.success == true)
{
setTimeout(function(){ location.reload(); }, 5000);
}
$.ajax("youurl", function(data){
if (data.success == true)
setTimeout(function(){window.location = window.location}, 5000);
})
)
오늘 이것을 조사한 후 호기심으로 여기에 많은 좋은 답이 있습니다. 사용하는 것이 최선이 아닙니다.setInterval보다setTimeout?
setInterval(function() {
location.reload();
}, 30000);
당신의 생각을 알려주세요.
그냥 사용.
$.ajax({
success: function (response) {
location.reload();
},
error : function(xhr,errmsg,err) {
console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
}
});
언급URL : https://stackoverflow.com/questions/27654298/jquery-refresh-reload-page-if-ajax-success-after-predicted-time
반응형
'programing' 카테고리의 다른 글
| Moment.js - 반올림하지 않고 날짜 이후의 연도를 얻으려면 어떻게 해야 합니까? (0) | 2023.09.26 |
|---|---|
| 어떤 상황에서 malloc이 NULL을 반환할 수 있습니까? (0) | 2023.09.26 |
| 머리글만 컬을 통해 php로 검색 (0) | 2023.09.26 |
| 다른 모듈에서 사용할 파이프를 글로벌하게 선언하는 방법은 무엇입니까? (0) | 2023.09.26 |
| GDB: 일반 포인터의 참조 해제 시도 (0) | 2023.09.26 |