JQuery 无刷新查询代码示例
本文导语: 1,前台页面 代码示例: JQuery 无刷新查询_www. function openAjax() { var val = document.getElementById('txt').value; var url = "VerifyUserNameHandler.ashx?para=" + val + "&date=" + new D...
1,前台页面
JQuery 无刷新查询_www.
function openAjax() {
var val = document.getElementById('txt').value;
var url = "VerifyUserNameHandler.ashx?para=" + val + "&date=" + new Date();
$.get(url, function (d) {
$("#resultSpan").html(d);
})
}
用户名:
2,后端代码
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(Names, _name) == -1)
{
context.Response.Write("恭喜,用户名可以使用。");
}
else
{
context.Response.Write("抱歉,用户名已被使用。");
}
}
public bool IsReusable {
get {
return false;
}
}
}