zoukankan      html  css  js  c++  java
  • Json+jquery+asp.net 返回数据库数据

    前台:

    代码
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    <title></title>
    <%--<script src="js/jquery-1.3.2.js" type="text/javascript"></script>--%>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
    $(document).ready(function() {
    $(
    "#btn").click(function() {
    $.getJSON(
    "show.ashx", //产生JSON数据的服务端页面
    function(json) {
    //循环取json中的数据,并呈现在列表中
    $.each(json, function(i) {
    $(
    "#list").append("<li>username:" + json[i].FuserName + "&nbsp; userPWD:" + json[i].FpassWord + "&nbsp; Fmail:" + json[i].Fmail + "&nbsp; Fadress:" + json[i].Fadress + "</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>

    后台:

    代码
    <%@ WebHandler Language="C#" Class="show" %>

    using System;
    using System.Web;
    using System.Collections.Generic;
    using System.Web.Script.Serialization;//添加此引用
    using DAL;
    using model;

    public class show : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
    JavaScriptSerializer serializer
    = new JavaScriptSerializer();
    IList
    <Tuser> tuser = UserDB.getList();
    string dt = serializer.Serialize(tuser);
    context.Response.ContentType
    = "text/plain";
    context.Response.Write(dt);
    }

    public bool IsReusable {
    get {
    return false;
    }
    }

    }

  • 相关阅读:
    JAVA语言中冒号的用法
    Tamper Data 安装与使用
    HTTP协议缓存策略深入详解之ETAG妙用
    HTTP协议
    HTTP协议----ETag
    super 使用以及原理
    __slots__用法以及优化
    归并排序详解(Python | Java实现)
    周刷题第二期总结(Longest Substring Without Repeating Characters and Median of Two Sorted Arrays)
    周刷题第一期总结(two sum and two numbers)
  • 原文地址:https://www.cnblogs.com/sheseido/p/1894865.html
Copyright © 2011-2022 走看看