... the report was formed for a long time. The hourglass and blue stripe tended to sleep. At first, he wanted a monkey that climbs the stairs, then a thermometer, but in the end there was a timer and a counter. A silly smile and a kind, sympathetic look makes wonders.
using System; namespace HTTPHandler_Test { public partial class TestForm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } } }
using System.Web; using System.Web.SessionState; namespace HTTPHandler_Test.HTTPHandler { /// <summary> /// HTTPHandlerTest /// </summary> public class HTTPHandlerTest : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { var counter = context.Request.QueryString["counter"]; int iCount; if (int.TryParse(counter, out iCount)) { counter = (++iCount).ToString(); } context.Response.Write(counter); } public bool IsReusable { get { return true; } } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="HTTPHandler_Test.TestForm" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="Script/jquery-1.10.2.min.js"></script> <script src="Script/askHTTPHandler.js"></script> </head> <body> <form id="form1" runat="server"> <div> <label id="lblStatus" style="display:block">: </label> <label id="lblCounter" style="display:block">: </label> <input type="button" id="btnStartStop" value="" onclick="AskHttpHandler()"/> </div> </form> </body> </html>
var start = false; function AskHttpHandler() { var dateStart = new Date(); var counter = 0; start = !start; if (start) { $('#btnStartStop').val(""); Ask(); } else $('#btnStartStop').val(""); function Ask() { var difInSeconds = Math.floor(((new Date()).getTime() - dateStart.getTime()) / 1000); var hours = Math.floor(difInSeconds / 3600); var minutes = Math.floor((difInSeconds - (hours * 3600)) / 60); var seconds = difInSeconds - (hours * 3600) - (minutes * 60); if (hours < 10) hours = "0" + hours; if (minutes < 10) minutes = "0" + minutes; if (seconds < 10) seconds = "0" + seconds; $('#lblStatus').text(": " + hours + ":" + minutes + ":" + seconds); var $ajaxQ = $.ajax({ type: "GET", async: false, url: "/HTTPHandler/HTTPHandlerTest.ashx", data: "counter=" + counter, success: onSuccessAsk, error: onErrorAsk }); var noop = function () { }; if ($ajaxQ != null) { $ajaxQ.onreadystatechange = $ajaxQ.abort = noop; $ajaxQ = null; } function onSuccessAsk(result) { counter = parseInt(result); $('#lblCounter').text(": " + result); if (start) setTimeout(Ask, 1000); } function onErrorAsk(result) { alert("error " + result.responseText); } }; }
var noop = function () { }; if ($ajaxQ != null) { $ajaxQ.onreadystatechange = $ajaxQ.abort = noop; $ajaxQ = null; }
Source: https://habr.com/ru/post/253875/
All Articles