通过js调用ashx中的test()方法
js:
function test(id,pwd){
$.ajax({
url: '/Tools/Handler.ashx?action=Log',
data:{id : id, pwd : pwd },
success: function (data){
alert(data);
}
});
}
一般处理程序(ashx):
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
namespace UAS2._0.Business.Common
{
/// <summary>
/// Common 的摘要说明
/// </summary>
public class Common : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string action = context.Request["action"].ToString();
switch (action)
{
case "PointForAjax":
PointForAjax(context);
break;
case "Log":
Log(context);
break;
default:
break;
}
}
public bool IsReusable
{
get
{
return true;
}
}
//公共js-Ajax返回状态码处理-数据库-字典-获取状态码
public void PointForAjax(HttpContext context)
{
string field = context.Request["field"].ToString();
List<sysDictionary> dictionaryList = DBManage.GetListBySql<sysDictionary>("SELECT * FROM [sys_Dictionary] where [field]='" + field + "'");
context.Response.Write(new JavaScriptSerializer().Serialize(dictionaryList));
}
//记录日志
public void Log(HttpContext context)
{
string source = context.ApplicationInstance.Request.UrlReferrer.AbsolutePath;
string warnAction = context.Request["warnAction"].ToString();
var user= context.Session["user"];
context.Session.Abandon();//清除全部Session,即退出登录
}
}
}