zoukankan      html  css  js  c++  java
  • WB AJax 例子2

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script src="Script/jquery-1.7.1.min.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="txtcode" type="text" />
            <input id="btn" type="button" value="查看" />
    
            <div id="name"></div>
            <div id="sex"></div>
            <div id="birthday"></div>
            <div id="nation"></div>
        </div>
        </form>
    
        <script type="text/javascript">
            $(document).ready(function () {
               
                $("#btn").click(function () {
                    //取值
                    var code = $("#txtcode").val();
                    //调AJax
                    $.ajax({
    
                        url: "Show.ashx",
                        type: "POST",
                        data: { code: code },
                        datatype: "XML",
                        success: function (data) {
    
                            $("#name").text($(data).find("Name").eq(0).text());
                            $("#sex").text($(data).find("Sex").text());
                            $("#nation").text($(data).find("Nation").text());
                            $("#birthday").text($(data).find("Birthday").text());
                        }
    
                    });
    
    
                })
    
            })
    
        </script>
    </body>
    </html>
    

      

    <%@ WebHandler Language="C#" Class="Show" %>
    
    using System;
    using System.Web;
    using System.Data;
    using System.Linq;
    using System.Data.Linq;
    
    
    public class Show : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            //取值
            string code = context.Request["code"].ToString();
            //操作数据库
            zxcDataContext _context = new zxcDataContext();
            //找到一条Info类型的数据
            Info data = _context.Info.Where(p => p.Code == code).First();
            //返回XML格式
            context.Response.Write("<?xml version='1.0'?>");
            context.Response.Write("<Info>");
            context.Response.Write("<Name>"+data.Name+"</Name>");
            context.Response.Write("<Sex>"+data.Sex.ToString()+"</Sex>");
            context.Response.Write("<Nation>"+data.Nation+"</Nation>");
            context.Response.Write("<Birthday>"+data.Birthday.Value.ToString("yyyy年MM月dd日")+"</Birthday>");
            context.Response.Write("<aa><Name>hello</Name></aa>");
            
            context.Response.Write("</Info>");
            context.Response.End();
            
            
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

      

  • 相关阅读:
    P3703 [SDOI2017]树点涂色
    CF1446D2 Frequency Problem (Hard Version)
    P3703 [SDOI2017]树点涂色
    ESP8266 Ticker库
    CSS 动画
    Sublime 安装
    XMLHttpRequest.responseText
    数据结构
    Linux 无需公网IP,远程SSH访问Linux服务器!
    Linux 安装
  • 原文地址:https://www.cnblogs.com/zhuxu/p/5082764.html
Copyright © 2011-2022 走看看