1. 程式人生 > >新增彈窗並跳轉

新增彈窗並跳轉

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!")