教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 JQuery 无刷新查询代码示例

JQuery 无刷新查询代码示例

发布时间:2015-12-05   编辑:jiaochengji.com
分享一个jquery无刷新查询的代码,通过后台代码验证用户名是否可用,不错的学习jquery无刷新处理数据的例子,有需要的朋友参考下。

1,前台页面
 

复制代码 代码示例:
<!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 id="Head2" runat="server">
    <title>jquery 无刷新查询_www.jbxue.com</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        function openAjax() {
            var val = document.getElementById('txt').value;
            var url = "VerifyUserNameHandler.ashx?para=" + val + "&date=" + new Date();
            $.get(url, function (d) {
                $("#resultSpan").html(d);
            })
        }       
    </script>
</head>
<body>
    <form id="form1" runat="server">
     用户名:<input type="text" id='txt' value="Sandy" onblur="openAjax();" />  <span id="resultSpan"></span>
    </form>
</body>
</html>

2,后端代码
 

复制代码 代码示例:

<%@ WebHandler Language="C#" Class="VerifyUserNameHandler" %>
using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
public class VerifyUserNameHandler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        //context.Response.ContentType = "text/plain";
        string _name = context.Request.QueryString["para"];
        _name = string.IsNullOrEmpty(_name) ? "" : _name;           
        System.Threading.Thread.Sleep(3000);//用线程来模拟数据库查询工作
        string[] Names = new string[] { "Sandy", "阿非", "abc" };//这里用Names数组来代替数据库中的结果集
        if (Array.IndexOf<string>(Names, _name) == -1)
        {
            context.Response.Write("恭喜,用户名可以使用。");
        }
        else
        {
            context.Response.Write("抱歉,用户名已被使用。");
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

您可能感兴趣的文章:
jquery局部刷新DIV及动态时钟显示iterator无法输出数据的问题
JQuery 无刷新查询代码示例
jquery 局部刷新(jsp环境)
jquery刷新页面 jquery局部刷新与及全页面刷新
刷新本页的多种html代码 iframe刷新代码
js控制网页自动刷新 刷新一次停止刷新
Jquery实现无闪烁定时刷新的代码
jQuery 定时局部刷新(setInterval)方法总结
JQuery FlexiGrid的asp.net完美解决方案 dotNetFlexGrid-.Net原生的异步表格控件
jQuery.Pjax

关键词: 查询  刷新   
[关闭]
~ ~