Reputation: 47
I need to find a way to slow down the reload of page that window.location.href
does.
This is needed because the animation of toggle button is not shown.
Is there a way?
Here code used:
$(".closeMan").change(function () {
if ($(this).prop("checked")) {
$.ajax({
type: "POST",
url: "./close_man.php",
success: function (result) {
window.location.href = window.location.href;
},
});
}
});
Upvotes: 0
Views: 869
Reputation: 1588
You can use a timeout, and window.location.reload():
setTimeout(function() {
window.location.reload();
}, 1000); // Time in milliseconds
Note: you cant call it like setTimeout(window.location.reload, 1000)
because you will get an Illegal invocation
error.
Upvotes: 1
Reputation: 645
You may use settimeout to handle timing problem.
$(".closeMan").change(function () {
if ($(this).prop("checked")) {
setTimeout(function(){
$.ajax({
type: "POST",
url: "./close_man.php",
success: function (result) {
window.location.href = window.location.href;
},
});
}
}, 1000);
});
Upvotes: 0
Reputation: 169407
Simply use setTimeout
(if you really need to slow down your application...):
$(".closeMan").change(function () {
if ($(this).prop("checked")) {
setTimeout(() => {
$.ajax({
type: "POST",
url: "./close_man.php",
success: () => {
window.location.href = window.location.href;
},
});
}, 500);
}
});
Upvotes: 2