加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

jQuery+Ajax实现限制查询间隔的方法

发布时间:2020-12-15 23:26:29 所属栏目:百科 来源:网络整理
导读:本篇章节讲解jQuery+Ajax实现限制查询间隔的方法。供大家参考研究具体如下: Jquery异步查询加载效果 using System;using System.Web;using System.Web.SessionState;//Handler.ashxpublic class Handler : IHttpHandler,IRequiresSessionState{ p

本篇章节讲解jQuery+Ajax实现限制查询间隔的方法。分享给大家供大家参考,具体如下:

Jquery异步查询加载效果
using System; using System.Web; using System.Web.SessionState; //Handler.ashx public class Handler : IHttpHandler,IRequiresSessionState { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string queryType = context.Request["queryType"]; string queryValue = context.Request["queryValue"]; if (context.Session["preQuery"] == null) //第一次查询 { context.Session["preQuery"] = queryValue + "@" + DateTime.Now.AddDays(-1); context.Session["currQuery"] = queryValue + "@" + DateTime.Now; } else //存在上次查询 { string[] preStrs = context.Session["currQuery"].ToString().Split('@'); context.Session["preQuery"] = queryValue + "@" + preStrs[1]; //重置为当前查询参数+上次查询时间 context.Session["currQuery"] = queryValue + "@" + DateTime.Now; } string[] strs=context.Session["preQuery"].ToString().Split('@'); if (strs[0] == queryValue) //同一请求限制查询间隔 { DateTime preTime = Convert.ToDateTime(strs[1]); DateTime nowTime = DateTime.Now; bool flag = CheckQueryTimeSpan(preTime,nowTime,3); if (flag) { context.Response.Write("查询间隔3秒"); } else { context.Response.Write("98"); } } context.Response.End(); } /// /// 判断本次查询和上次查询间隔是否小于指定秒数 /// /// /// /// /// public bool CheckQueryTimeSpan(DateTime preTime,DateTime nowTime,int timeSpan) { TimeSpan ts = nowTime - preTime; int difference = ts.Seconds; bool flag = (difference < timeSpan) ? true : false; return flag; } public bool IsReusable { get { return false; } } }

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》

希望本文所述对大家jQuery程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!