欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery+Ajax實現(xiàn)限制查詢間隔的方法

 更新時間:2016年06月07日 10:20:11   作者:smartsmile2012  
這篇文章主要介紹了jQuery+Ajax實現(xiàn)限制查詢間隔的方法,涉及jQuery的ajax方法參數(shù)設(shè)置及asp.net后臺交互的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了jQuery+Ajax實現(xiàn)限制查詢間隔的方法。分享給大家供大家參考,具體如下:

<%@ 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="JS/jquery-1.9.1.js" type="text/javascript"></script>
  <link href="Styles/Site.css" rel="stylesheet" type="text/css" />
  <style type="text/css">
  .span_query { cursor:pointer;}
  </style>
  <script type="text/javascript">
    $(function () {
      $(".span_query").click(function () {
        var val = $(this).attr("data-value");
        var id = $(this).attr("id");
        AjaxQuery($(this),val);
      });
    });
    function AjaxQuery(obj, v) {
      $.ajax({
        url: 'Ajax/Handler.ashx?queryType=score&queryValue=' + v,
        type: 'POST',
        dataType: 'text',
        timeout: 10000,
        cache: false,
        beforeSend: LoadFunction,
        error: erryFunction,
        success: succFunction
      })
      function LoadFunction() {
        obj.html('<img src="Images/loading02.gif" />');
      }
      function erryFunction() {
        obj.html('error');
      }
      function succFunction(tt) {
        obj.html('');
        obj.html(tt);
      }
    }
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <table style="width:100%" class="gvCss">
    <tr class="head"><td style="width:10%;">姓名</td><td style="width:30%;">語文</td><td style="width:30%;">數(shù)學(xué)</td><td style="width:30%;">英語</td></tr>
    <tr><td>張三</td>
      <td id="query1" title="點擊查詢" class="span_query" data-value="1">查詢</td>
      <td id="query2" title="點擊查詢" class="span_query" data-value="2">查詢</td>
      <td id="query3" title="點擊查詢" class="span_query" data-value="3">查詢</td></tr>
  </table>
  </div>
  </form>
</body>
</html>

<%@ 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]; //重置為當(dāng)前查詢參數(shù)+上次查詢時間
      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>
  /// 判斷本次查詢和上次查詢間隔是否小于指定秒數(shù)
  /// </summary>
  /// <param name="preTime">上次查詢時間</param>
  /// <param name="nowTime">本次查詢時間</param>
  /// <param name="timeSpan">指定秒數(shù)</param>
  /// <returns></returns>
  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;
    }
  }
}

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

  • jQuery3.0中的buildFragment私有函數(shù)詳解

    jQuery3.0中的buildFragment私有函數(shù)詳解

    在 jQuery3.0中,buildFragment 是一個私有函數(shù),用來構(gòu)建一個包含子節(jié)點 fragment 對象。下文給大家介紹jQuery3.0中的buildFragment私有函數(shù)詳解,對jquery3.0 buildfragment相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧
    2016-08-08
  • jQuery的deferred對象使用詳解

    jQuery的deferred對象使用詳解

    deferred對象就是jQuery的回調(diào)函數(shù)解決方案。在英語中,defer的意思是"延遲",所以deferred對象的含義就是"延遲"到未來某個點再執(zhí)行。
    2016-09-09
  • 詳解jQuery的Cookie插件

    詳解jQuery的Cookie插件

    本文對jQuery的Cookie插件的使用方法和具體實例進行系統(tǒng)介紹,有需要的朋友可以看下
    2016-11-11
  • jQuery的.live()和.die() 使用介紹

    jQuery的.live()和.die() 使用介紹

    很多開發(fā)者都知道jQuery的.live()方法,他們大部分知道這個函數(shù)做什么,但是并不知道是怎么實現(xiàn)的,所以用的并不那么舒適。而且他們卻從未聽過還有解除綁定的.live()事件的.die()方法。即使你熟悉這些,但是你意識到.die()了嗎?
    2011-09-09
  • jQuery制作仿騰訊web qq用戶體驗桌面

    jQuery制作仿騰訊web qq用戶體驗桌面

    ,酷炫個性的desktop桌面特效展示支持各大主流瀏覽器IE6以上,感興趣的朋友可以體驗下哈
    2013-08-08
  • jQuery下的幾個你可能沒用過的功能

    jQuery下的幾個你可能沒用過的功能

    用jQuery好久了,都做了兩個項目了。今兒晚上喝咖啡喝多了,這都兩點多了睡不著,給大家分享下我在項目中用到的一些用jQuery實現(xiàn)的一些比較好的功能。希望對一些新手有點用。。。高手們可以拍磚哈。。。。我頭很硬不怕疼。。。呵呵。
    2010-08-08
  • 使用jquery清空、復(fù)位整個輸入域

    使用jquery清空、復(fù)位整個輸入域

    這篇文章主要介紹了使用jquery清空、復(fù)位整個輸入域,非常的簡單實用,這里推薦給大家,需要的朋友可以參考下
    2015-04-04
  • jQuery學(xué)習(xí)筆記之基礎(chǔ)中的基礎(chǔ)

    jQuery學(xué)習(xí)筆記之基礎(chǔ)中的基礎(chǔ)

    本文是jQuery學(xué)習(xí)筆記系列文章的第一篇,跟大多數(shù)開篇文章一樣,我們來講解下jQuery最基礎(chǔ)的東西,希望大家能夠喜歡。
    2015-01-01
  • 運用jquery實現(xiàn)table單雙行不同顯示并能單行選中

    運用jquery實現(xiàn)table單雙行不同顯示并能單行選中

    (該方法是對《運用jquery實現(xiàn)(table)單雙行不同顯示并能多行選中》的改進,適合于單行選擇)
    2009-07-07
  • Jquery實現(xiàn)視頻播放頁面的關(guān)燈開燈效果

    Jquery實現(xiàn)視頻播放頁面的關(guān)燈開燈效果

    使用Jquery實現(xiàn)視頻播放頁面的關(guān)燈開燈效果。其中視頻顯示使用embed 元素,該元素是html5的元素,所以使用支持html5的瀏覽器效果會更好,具體實現(xiàn)代碼如下,感興趣的朋友可以參考下
    2013-05-05

最新評論