Hardik Patel

Hardik Patel

  • NA
  • 378
  • 467.5k

how to refresh particular div using web service?

Dec 21 2013 2:34 AM
 i am using below code to refresh particular div with time interval
 but it's not working



<script type="text/javascript">
        $(document).ready(
            function () {
                setInterval(function () {
                    ShowCurrentTime();
                }, 3000);
            });
        function ShowCurrentTime() {
            $.ajax({
                type: "POST",
                url: "ARcalls.aspx/Getcount",             // webmethod
                data: '{UserId : "' + $("#<%=Label2.ClientID%>")[0].value + '"}',     // paramater pass to webmethod from masterpage
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                   alert(response.d);
                }
            });
        }
        function OnSuccess(response) {
            $('#show').text('I am getting refreshed');
        }




ARcall.aspx.cs

ARCall.aspx/Getcount

 [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]

 public string Getcount(string UserID)
    {
        //UserID = Convert.ToString(Session["UserId"]).ToString();
        SqlConnection cn =
            new SqlConnection(ConfigurationSettings.AppSettings["CnnStr"]);
        SqlCommand cmd = new SqlCommand("SELECT count([id]) FROM [AR] WHERE ([UserID] = @UserID and outcome in ('Asked to Call back','Not reachable','Not recieved'))", cn);
        cmd.Parameters.Add("UserID", UserID);
        String unitsInStock = "";
        cn.Open();
        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
        {
            while (dr.Read())
                unitsInStock = dr[0].ToString();
        }
        //System.Threading.Thread.Sleep(3000);
        return unitsInStock;
    }




Answers (3)