handler.ashx

来自「利用js实现与服务器的异步交互」· ASHX 代码 · 共 37 行

ASHX
37
字号
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/xml";
        string PovinceID = context.Request["id"];
        Data db = new Data();
        System.Data.DataTable AimDt = db.GetCity(PovinceID);
        System.Text.StringBuilder xml = new System.Text.StringBuilder();
        xml.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Root>");
        for (int i = 0; i < AimDt.Rows.Count; i++)
        {
            xml.Append("<citys>");
            for (int j = 0; j < AimDt.Columns.Count; j++)
            {
                string caption = AimDt.Columns[j].Caption;
                string text = AimDt.Rows[i][j].ToString();
                xml.Append("<" + caption + ">" + text + "</" + caption + ">");
            }
            xml.Append("</citys>");
        }
        xml.Append("</Root>");
        context.Response.Write(xml.ToString());
    }

    public bool IsReusable
    {
        get {
            return false;
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?