前台<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %><!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>无标题页</title> <script src="jquery-1.3.2.js" type="text/javascript"></script> <script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#btn").click(function() {
$.getJSON(
"Handler1.ashx", //产生JSON数据的服务端页面
function(json) {
//循环取json中的数据,并呈现在列表中
$.each(json, function(i) {
$("#list").append("<li>name:" + json[i].Name + " address:" + json[i].Address + " Pwd:" + json[i].Pwd + " Url:" + json[i].Url + "</li>");
});
});
});
});
</script></head>
<body>
<form id="form1" runat="server">
<div>
<h3 title="选择一个分区">
<span>选择</span></h3>
<input id="btn" type="button" value="获取数据" />
<ul id="list">
</ul>
</div>
</form>
</body>
</html>一般处理页面using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;namespace WebApplication2
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Handler1 : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
SqlConnection sqlConnection = new SqlConnection("server=.;databaset=pubs;uid=sa;pwd=sa");
DataSet ds = new DataSet();
string strSql = "select * from dbo.T_UserTable";
SqlDataAdapter da = new SqlDataAdapter(strSql, sqlConnection);
JavaScriptSerializer serializer = new JavaScriptSerializer();
//调用后台方法
//序列化
string date = serializer.Serialize(da.Fill(ds, "dbo.T_UserTable"));
context.Response.Write();
} public bool IsReusable
{
get
{
return false;
}
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title> <script src="jquery-1.3.2.js" type="text/javascript"></script> <script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#btn").click(function() {
$.getJSON(
"Handler1.ashx", //产生JSON数据的服务端页面
function(json) {
//循环取json中的数据,并呈现在列表中
$.each(json, function(i) {
$("#list").append("<li>name:" + json[i].Name + " address:" + json[i].Address + " Pwd:" + json[i].Pwd + " Url:" + json[i].Url + "</li>");
});
});
});
});
</script></head>
<body>
<form id="form1" runat="server">
<div>
<h3 title="选择一个分区">
<span>选择</span></h3>
<input id="btn" type="button" value="获取数据" />
<ul id="list">
</ul>
</div>
</form>
</body>
</html>一般处理页面using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;namespace WebApplication2
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Handler1 : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
SqlConnection sqlConnection = new SqlConnection("server=.;databaset=pubs;uid=sa;pwd=sa");
DataSet ds = new DataSet();
string strSql = "select * from dbo.T_UserTable";
SqlDataAdapter da = new SqlDataAdapter(strSql, sqlConnection);
JavaScriptSerializer serializer = new JavaScriptSerializer();
//调用后台方法
//序列化
string date = serializer.Serialize(da.Fill(ds, "dbo.T_UserTable"));
context.Response.Write();
} public bool IsReusable
{
get
{
return false;
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货