乱码乱a∨中文字幕,在线免费激情视频,亚洲欧美久久夜夜潮,国产在线网址

  1. <sub id="hjl7n"></sub>

    1. <sub id="hjl7n"></sub>

      <legend id="hjl7n"></legend>

      當(dāng)前位置:首頁(yè) >  站長(zhǎng) >  編程技術(shù) >  正文

      Asp.net基于ajax和jquery-ui實(shí)現(xiàn)進(jìn)度條

        阿里云優(yōu)惠券 先領(lǐng)券再下單

      這篇文章主要介紹了Asp.net基于ajax和jquery-ui實(shí)現(xiàn)進(jìn)度條,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

      前臺(tái)用ajax不停進(jìn)行查詢,直到任務(wù)完成。進(jìn)度條用的是jquery-ui。后臺(tái)用一般處理程序處理相應(yīng),進(jìn)度信息保存在HttpContext.Application中。

      代碼作為簡(jiǎn)單示例,實(shí)際應(yīng)用時(shí)應(yīng)對(duì)資源釋放、防止多線程混亂等做進(jìn)一步控制。

      效果圖:

      代碼:

      前臺(tái):

      <!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script src="Scripts/jquery-2.1.4.min.js"></script>
        <script src="Scripts/jquery-ui-1.11.4.min.js"></script>
        <link href="Content/themes/base/all.css" rel="external nofollow" rel="stylesheet" />
        <script type="text/javascript">
          function GetProgress() {
            $.ajax({
              url: "/Handler1.ashx",
              type: "POST",
              data: { "RequestType": "AjaxRequest", "Method": "GetProgress" },
              success: function (data) {
                if (data != -1) {
                  //工作沒有結(jié)束,繼續(xù)查詢進(jìn)度
                  setTimeout(GetProgress, 100);
                  $("#progress").html(data);
                  $("#progressbar").progressbar({ value: parseInt(data) });
                } else {
                  //工作完成
                  $("#progress").html("done");
                  $("#progressbar").progressbar({ value: 100 });
                  $("#btn1").attr("disabled", false);
                }
              }
            });
          }

          function DoWork() {
            //禁用按鈕
            $("#btn1").attr("disabled", true);
            $.ajax({
              url: "/Handler1.ashx",
              type: "POST",
              data: { "RequestType": "AjaxRequest", "Method": "DoWork" }
            });
            //開始查詢進(jìn)度
            setTimeout(GetProgress, 500);
          }
        </script>

      </head>
      <body>
        <div>
          <input type="button" id="btn1" value="開始" onclick="DoWork();" />
          <label id="progress"></label>
          <div id="progressbar"></div>
        </div>
      </body>
      </html>

      后臺(tái):

      // 2015年12月16日 09:53:11
      // David Huang
      // 進(jìn)度條示例
      namespace ProgressTest
      {
        using System;
        using System.Threading;
        using System.Web;

        /// <summary>
        /// Handler1 的摘要說(shuō)明
        /// </summary>
        public class Handler1 : IHttpHandler
        {
          // context
          private HttpContext context;

          public bool IsReusable
          {
            get
            {
              return false;
            }
          }

          public void ProcessRequest(HttpContext context)
          {
            this.context = context;
            if (context.Request["RequestType"] == "AjaxRequest")
            {
              if (context.Request["Method"] == "GetProgress")
              {
                context.Response.Clear();
                context.Response.Write(this.GetProgress());
                context.Response.End();
              }
              else
              {
                this.DoWork();
              }
            }
          }

          /// <summary>
          /// 開始工作
          /// </summary>
          private void DoWork()
          {
            for (int i = 0; i < 100; i++)
            {
              // 記錄進(jìn)度
              // 實(shí)際應(yīng)用中需要進(jìn)一步控制(利用用戶信息、cookies等),防止并發(fā)造成混亂
              this.context.Application["progress"] = i + 1;
              Random r = new Random();
              Thread.Sleep(r.Next(10, 100));
            }
            // 完成后釋放資源
            this.context.Application["progress"] = null;
          }

          /// <summary>
          /// 查詢進(jìn)度
          /// </summary>
          /// <returns>進(jìn)度</returns>
          private int GetProgress()
          {
            if (this.context.Application["progress"] != null)
            {
              return (int)this.context.Application["progress"];
            }
            else
            {
              return -1;
            }
          }
        }
      }

      以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

      來(lái)源:腳本之家

      鏈接:https://www.jb51.net/article/201282.htm

      申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

      相關(guān)標(biāo)簽
      asp.net
      .net開發(fā)

      相關(guān)文章

      熱門排行

      信息推薦