爪哇一角

          共同探討STRUTS#HIBERNATE#SPRING#EJB等技術
          posts - 3, comments - 6, trackbacks - 0, articles - 99
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          easyui-progressbar實例!

          Posted on 2016-03-23 15:05 非洲小白臉 閱讀(559) 評論(0)  編輯  收藏 所屬分類: AJAX + jQuery
          jsp:<div id="p" class="easyui-progressbar" style="width:400px;"></div>

          js:
          var timerId;
          // 初始化方法
          function init(){
          //每隔0.5秒自動調用方法,實現進度條的實時更新
          timerId=window.setInterval(getProgress,500);
          $.ajax({
             dataType: "json",
             method: "post",
             url: contextPath+"/XXXX/clearProgress.do"
          })
          $("#p").show();
          $('#p').window({
          title:'進度條',
          width:420,
          height:50,
          modal:true,
          minimizable:false,
          maximizable: false,
          closed: false,
          collapsible:false
          });
          };
          function getProgress()
          {
          $.ajax({
             dataType: "json",
             method: "post",
             url: contextPath+"/XXX/getProgress.do"
          }).done(function(data){
          if(data.processInt>=100){
                      window.clearInterval(timerId);
                      $('#p').window('close');
                   }
                   $('#p').progressbar('setValue',data.processInt);
              }).fail(function(){
              $.messager.alert('告警',"本次操作失敗,請重新操作",'error');
          return false;
              });
          }

          java:
          int processInt = 0;
              /**
               * 
               * ??
               * @author 
               * @param 
               * @param 
               * @return
               * @see [類、類#方法、類#成員]
               */
              @RequestMapping(value = "/clearProgress", method = RequestMethod.POST)
              public @ResponseBody void clearProgress()
              {
                  processInt = 0;
              }
              /**
               * 
               * ??
               * @author 
               * @param 
               * @param 
               * @return
               * @see [類、類#方法、類#成員]
               */
              @RequestMapping(value = "/getProgress", method = RequestMethod.POST)
              public @ResponseBody Map<String, Object> getProgress()
              {
                  Map<String, Object> map = new HashMap<String, Object>();
                  try
                  {
                      Random random=new Random();
                      processInt += random.nextInt(10);
                  }
                  catch (Exception e)
                  {
                      log.error("Exception:", e);
                  }
                  map.put("processInt", processInt);
                  return map;
              }

          實際項目中,只要將后臺處理的過程的進度實時傳遞給公共變量processInt 即可。
          主站蜘蛛池模板: 岗巴县| 花垣县| 迁安市| 肥城市| 涿鹿县| 大邑县| 阿城市| 云龙县| 东港市| 赤峰市| 泰来县| 安仁县| 沙田区| 南和县| 宁陵县| 京山县| 郧西县| 永丰县| 饶阳县| 杂多县| 兴隆县| 长顺县| 郧西县| 临汾市| 金川县| 开鲁县| 格尔木市| 洞口县| 依兰县| 天峨县| 吴江市| 梓潼县| 永年县| 民乐县| 霍山县| 卢氏县| 乐山市| 佛学| 和顺县| 崇仁县| 许昌县|