本文实例讲述了jQuery+Ajax实现限制查询间隔的方法。分享给大家供大家参考,具体如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Jquery20150305.aspx.cs" Inherits="Jquery20150305" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Jquery异步查询加载效果</title> <script src="/UploadFiles/2021-04-02/jquery-1.9.1.js"><%@ WebHandler Language="C#" Class="Handler" %> 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(); } /// <summary> /// 判断本次查询和上次查询间隔是否小于指定秒数 /// </summary> /// <param name="preTime">上次查询时间</param> /// <param name="nowTime">本次查询时间</param> /// <param name="timeSpan">指定秒数</param> /// <returns></returns> public bool CheckQueryTimeSpan(DateTime preTime, DateTime nowTime, int timeSpan) { TimeSpan ts = nowTime - preTime; int difference = ts.Seconds; bool flag = (difference < timeSpan) "_blank" href="https://www.jb51.net/Special/93.htm">jquery中Ajax用法总结》、《jQuery表格(table)操作技巧汇总》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》希望本文所述对大家jQuery程序设计有所帮助。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- [电影原声带]黎允文《天将雄师》[FLAC+CUE]
- 曝NS继任机型已进入量产阶段:已花了30亿日元
- 不是Switch2?曝《马里奥惊奇》NS捆绑包即将公开
- 暖心任天堂!网友Switch维修返还时贴纸被完好保留
- 《国语老歌 经典对唱情歌 2CD》[WAV/分轨][1.1GB]
- 《刀郎 翻唱精选华语专辑 披着羊皮的狼 》[WAV+CUE][430MB]
- 《真的田震 中国乐坛红极一时的歌者 精品集》[WAV+CUE][300MB]
- 群星.1995-新滚石九大天王之情歌大全【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·纵夏欢唱【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·贺岁齐唱【滚石】【WAV+CUE】
- 黑神话悟空上品虫校尉精魄获取方法一览|上品虫校尉精魄收集攻略
- 《指环王:夏尔的传说》推迟至2025年初发行
- 黑神话悟空上品蝎太子精魄获取方法一览|上品蝎太子精魄收集攻略
- 银霞.1977-《台北66电影原声带》台湾复刻版[WAV+CUE]
- 银霞.1980-《你那好冷的小手》台湾珍藏纪念版[WAV+CUE]