Ajax中添加弹窗并setTImeout延迟跳转:
$.ajax({
type: 'POST',
url: '',
data: formData,
success: function(response){
if (response.status == 'ok'){
$('.container').prepend('<div id="alertBanner" class="alert alert-success mr-2 ml-2 mt-2">Your email has been updated!</div>');
setTimeout(function() {
window.location.href = response.data.redirect;
}, 1000);
} else if (response.status == 'error'){
...
}
}
在后端跳转并添加弹窗:
from django.contrib import messages
messages.add_message(request, messages.SUCCESS, "Your email has been updated!")