新增彈窗並跳轉
阿新 • • 發佈:2019-02-08
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!")