如题求助!.NET中怎样将webform中的一个变量a传到一般处理器程序.ashx.cs中?
//前端
var para = { "cmd": "Test_1", "id": 1 };
$.ajax({
type: "POST",
url: "AJAX.ashx?d=" + new Date(),
data: para,
dataType: "json",
success: function (json) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + "," + errorThrown);
}
});
//后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
namespace Web
{
///
/// Author: yenange
/// Date : 2014-07-31
/// Description: ajax请求的通用的一般处理程序
///
public class AJAX : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string requestMethod = context.Request["cmd"];
string result=string.Empty;
switch (requestMethod)
{
#region [ Test ]
case "Test_1":
int id = CONVERT.ToInt32(context.Request["id"]);
result = Newtonsoft.Json.JsonConvert.SerializeObject(id);
break;
#endregion
}
context.Response.ContentType = "text/plain";
context.Response.Write(result);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
用ajax或者表单提交到ashx,ashx用Request对象获取