【问题标题】:Jquery Ajax call in asp.net Progress Bar updatejquery Ajax调用asp.net进度条更新
【发布时间】:2013-08-26 07:49:20
【问题描述】:

我在 asp.net 中进行 jquery ajax 调用,我从文本框中的数据库中获取一些值,并在此基础上制作 jquery 进度条。 它在文本框中获取值,但第一次没有获取进度条的值,我必须重新加载页面以获得进度条的值。
下面是我的代码

 $(function () {
        GetValue();
        var l_count= parseInt($("#txtcount").val());

        $("#sliderlicense").progressbar({
            max: 100,
            value: l_count
        });           
    });

    function GetValue() {
        $.ajax({
            type: "POST",
            url: "MyPage.aspx/GetCount", //url to point your webmethod     
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (Result) {
                $("#txtcount").val(Result.d);
            },
            error: function () { alert('error'); }
        });
    }


 [System.Web.Services.WebMethod()]
        public static string GetCount()
        {
          //Get values from DB and return it
        }

我也尝试了 document.ready 但没有运气,我应该使用 Jquery 的哪个事件来制作我的进度条。

【问题讨论】:

    标签: c# jquery asp.net


    【解决方案1】:

    试试这个:

    async:false, 添加到 ajax 调用

    $(document).ready(function(){
            GetValue();
            var l_count= parseInt($("#txtcount").val());
    
            $("#sliderlicense").progressbar({
                max: 100,
                value: l_count
            });
    
        });
    })
    function GetValue() {
        $.ajax({
            type: "POST",
            url: "MyPage.aspx/GetCount", //url to point your webmethod     
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async:false,
            success: function (Result) {
                $("#txtcount").val(Result.d);
            },
            error: function () { alert('error'); }
        });
    }
    

    【讨论】:

      【解决方案2】:

      ajax 表示Asynchronous,也就是说,你需要等到你的第一个请求成功,然后处理价值。

      一些伪代码:

       $.ajax({
              type: "POST",
              url: "MyPage.aspx/GetCount", //url to point your webmethod     
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (Result) {
                  $("#txtcount").val(Result.d);
      
                  //HERE ASSIGN TO PROGRESS BAR 
                  var l_count= parseInt($("#txtcount").val());
      
                  $("#sliderlicense").progressbar({
                   max: 100,
                   value: l_count
                  });
                  // --------------------------
              },
              error: function () { alert('error'); }
          });
      

      【讨论】:

        猜你喜欢
        • 2012-12-08
        • 1970-01-01
        • 2012-06-17
        • 2010-10-22
        • 1970-01-01
        • 2011-12-21
        • 1970-01-01
        • 2011-02-13
        • 1970-01-01
        相关资源
        最近更新 更多