国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net線程批量導入數據時通過ajax獲取執行狀態

2024-07-10 12:49:25
字體:
來源:轉載
供稿:網友

前言

最近因為工作中遇到一個需求,需要做了一個批量導入功能,但長時間運行沒個反饋狀態,很容易讓人看了心急,產生各種臆想!為了解決心里障礙,寫了這么個功能。

通過線程執行導入,并把正在執行的狀態存入session,既共享執行狀態,通過ajax調用session里的執行狀態,從而實現反饋導入狀態的功能!

上代碼: 前端頁面

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>批量導入數據</title> <style type="text/css">  .pop_body_con { width: 310px; position: fixed; top: 50%; left: 50%; margin-left: -150px; background: #eee; display:none; }   .pop_body_con .pop_head { width: auto; padding: 10px 0; background: #fff; }    .pop_body_con .pop_head a { display: block; color: #717274; font-size: 12px; text-decoration: none; text-align: center; }  .pop_box { width: auto; overflow: hidden; padding: 45px 10px; }   .pop_box .pop_text { float: left; }    .pop_box .pop_text p { padding: 0; margin: 0; font-size: 12px; line-height: 18px; color: #717274;}   .pop_box .progress_bar_con { float: left; width: 220px; position: relative; z-index: 2; }    .pop_box .progress_bar_con p { margin: 0; padding: 0; font-size: 12px; color: #fff; line-height: 18px; width: 100%;             text-align: center; position: absolute; left: 0; top: 0; z-index: 4; }    .pop_box .progress_bar_con .progress_bar_start { width: 100%; height: 18px; background: #C4C0C0; }    .pop_box .progress_bar_con .progress_bar_end { width: 16%; height: 18px; background: #2bd35d; position: absolute; left: 0; top: 0; z-index: 3; }   .pop_box .progress_bar_con { float: left; }  #loading-mask { width: 100%; height: 100%; position: fixed; top: 0px; left: 0px; z-index: 0; background-color: rgba(0, 0, 0, 0.34902); display: none; } </style> <script src="ajax-master/jquery.js"></script> <script>  var MyInterval;  $(function () {   $("#startImport").click(function () {    MyInterval = setInterval(getState, 1000);   });  });    function getState() {   $.ajax({    url: "test.aspx",    type: "Post",    data: { action: "getSession" },    success: function (msg) {     if (msg != "null") {      msg = eval('(' + msg + ')');      if (msg.being == 100) {       setProcessBar(1, 1);       $(".pop_body_con").hide();       $("#loading-mask").hide();       clearInterval(MyInterval);      }      else {       $(".pop_body_con").show();       $("#loading-mask").show();       setProcessBar(msg.being, msg.count)      }     }    }   });  }  function setProcessBar(exeFlag, exeMax) {   $("#progressbar_text").html(parseInt(roundFun(exeFlag / exeMax, 2) * 100) + "%");   $("#progressbar_bar").attr("style", "width:" + parseInt(roundFun(exeFlag / exeMax, 2) * 100) + "%;");  }  function roundFun(number, X) {   X = (!X ? 2 : X);   return Math.round(number * Math.pow(10, X)) / Math.pow(10, X);  } </script></head><body style="background-color: #fff;"> <input id="startImport" type="button" value="導入數據" /> <div id="loading-mask" ></div> <div class="pop_body_con">  <div class="pop_head">   <a href="javascript:;">正在導入…請勿操作!</a>  </div>  <div class="pop_box">   <div class="pop_text">    <p>導入進度:</p>   </div>   <div class="progress_bar_con">    <p id="progressbar_text">0%</p>    <div class="progress_bar_start"></div>    <div class="progress_bar_end" id="progressbar_bar"></div>   </div>  </div> </div></body></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 团风县| 花垣县| 西宁市| 贡嘎县| 阿拉善左旗| 宁津县| 井陉县| 静乐县| 桓台县| 武城县| 文昌市| 岳阳市| 施甸县| 尼玛县| 年辖:市辖区| 新河县| 永寿县| 都兰县| 安陆市| 林甸县| 镇安县| 铜山县| 尼木县| 长泰县| 无棣县| 永靖县| 新平| 昌图县| 航空| 易门县| 大新县| 辰溪县| 额济纳旗| 盖州市| 乐业县| 铁岭县| 南靖县| 保定市| 乌兰县| 黄陵县| 钟祥市|