复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient; //引入命名空间
using System.Data;
namespace 加载层
{
///
/// $codebehindclassname$ 的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Readdata: IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
//获取外部传进来的变量值i
int i = Int32.Parse(context.Request.QueryString["i"]);
//连接数据库
SqlConnection con = new SqlConnection("data source=.;user id=sa;pwd=5239898;database=librarydatabase;");
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from reader where 序号='" + i + "'", con);
SqlCommandBuilder com = new SqlCommandBuilder(ada);
DataSet ds = new DataSet();
ada.Fill(ds, "reader");
con.Close();
//读取表中栏位为“姓名”的字段值,并传出
context.Response.Write(ds.Tables["reader"].Rows[0]["姓名"].ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
然后我们需要新建一个Javascript文件,命名为loaddata.js。输入如下代码:
复制代码 代码如下:
$("document").ready(function() {
$("a[href=javascript]").click(function() {
chkform();
return false;
})
$("a[href=test]").click(function() {
$("#load").css("display", "none");
$("#mark").css("display", "none");
return false;
})
});
var chkform = function() {
new Request({
url: 'ReadData.ashx?i=' + $("#Text1").attr("value"),
onSuccess: function(txt) {
$("#load").append("
" + txt + "
");$("#load").css("display", "block");
$("#mark").css("display", "block");
},
onRequest: function() {
$("#load").append("
正在加载
");},
onFailure: function() {
alert('信息加载失败!');
}
}).send();
}
还没完,我们还要新增一个CSS文件,命名为main.css,深入如下样式:
复制代码 代码如下:
#mark{
width: 100%;
background-color:White;
position:absolute;
left: 0px;
top: 0px;
height: 700px;
filter:alpha(opacity=70);
-moz-opacity:70;
opacity:70;
z-index:2;
display:none;
}
#load
{
background-color:Gray;
border: 1px solid #999;
font-size: 12px;
position:relative;
margin:0 auto;
margin-top:100px;
width:200px;
height:150px;
z-index:99;
display:none;
}
我们在网站的首页里面源码输入如下代码:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="加载层._Default" %>
//记得引入这个javascript库文件
//VS支持智能提示的文件,可有可无
//记得引入JQuery
点击加载
load 试试
至此完成了我们要的效果。
效果图及DEMO一会放出。
看上面的链接以及文本框都处于“灰色”状态,不可编辑。点击中间弹出层的链接可以回到最初状态。整个过程中页面都没有刷新!
Demo下载地址: http://xiazai.jb51.net/200911/yuanma/asp.net_jquery_jiazaiceng.rar



