ajax异步请求的ashx页面

首先创建一般处理程序,也就是ashx 文件

然后就是要让异步请求的数据不被浏览器缓存

其次获得请求的参数

再次根据参数进行具体的业务逻辑操作

最后返回响应的字符串

下面给出一个简单的例子

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace WXWebTest.AJAX
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Test : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Buffer = true;//缓存输出
#region 禁用浏览器缓存
context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
context.Response.AddHeader("pragma", "no-cache");
context.Response.AddHeader("cache-control", "");
context.Response.CacheControl = "no-cache";
#endregion
string result = "";
string qs = context.Request.Params["a"];//获取参数 可以根据参数进行具体的业务
result = qs + "hello world";//具体的ToDo部分可以在这里
context.Response.Write(result);
}

public bool IsReusable
{
get
{
return false;
}
}
}
}
原文地址:https://www.cnblogs.com/wxzl/p/2287420.html