通过轮询实现消息弹窗提醒

  • A+
所属分类:MVC

通过轮询实现消息弹窗提醒

Html

  1. <!DOCTYPE html>  
  2.   
  3. <html>  
  4. <head>  
  5.     <meta name="viewport" content="width=device-width" />  
  6.     <title>State_Restart</title>  
  7.     <link href="~/Contents/css/bootstrap.min14ed.css" rel="stylesheet" />  
  8.   
  9. </head>  
  10. <body>  
  11.     <div class="panel panel-danger" style="width:340px;height:215px;">  
  12.         <div class="panel-heading">  
  13.             通知  
  14.         </div>  
  15.         <div class="panel-body" style="text-align:center">  
  16.             <p>系统将在1分钟后重启,请保存好当前操作!!!</p>  
  17.         </div>  
  18.     </div>  
  19.     <script src="~/Contents/js/jquery.min.js"></script>  
  20.     <script src="~/Contents/js/bootstrap.min.js"></script>  
  21.     <script src="~/Contents/js/layer/layer.js"></script>  
  22.     <script src="~/Contents/js/plugins/layer/laydate/laydate.js"></script>  
  23. </body>  
  24. </html>  

JavaScript

  1. $(document).ready(function () {  
  2.     var t = setInterval(function () {   
  3.     $.post("/Notice/State", function (a) {  
  4.             if (a == "1") {  
  5.                 //iframe窗  
  6.                 layer.open({  
  7.                     type: 2,  
  8.                     title: false,  
  9.                     closeBtn: 1, //不显示关闭按钮  
  10.                     shade: [0],  
  11.                     shadeClose: true,  
  12.                     area: ['340px', '215px'],  
  13.                     offset: 'rb', //右下角弹出  
  14.                     time: 3000, //2秒后自动关闭  
  15.                     anim: 2,  
  16.                     content: ['/Notice/State_Restart', 'no'],//iframe的url,no代表不显示滚动条  
  17.                 });  
  18.                // clearInterval(t);  
  19.             }  
  20.             else {  
  21.                 // alert("2");  
  22.             }  
  23.         });  
  24.     },15000);  
  25. });  

Controller

  1. public void State()  
  2.         {  
  3.             var result = sql.NOTICE.Where(r => r.STATE == "1");  
  4.             if (result.Count() == 1)  
  5.             {  
  6.                 Response.Write("1");  
  7.             }  
  8.             else  
  9.             {  
  10.                 Response.Write("0");  
  11.             }  
  12.         }  
钰玺

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: