ajax请求ashx数据,在ashx中当session为空时要跳转页面
如题,前台ajax请求ashx代码如下:
$(document).ready(function () {
$.ajax(
{
async: false,
cache: false,
type: "POST",
url: "Ashx/getSysMenu.ashx",
success: function (data) {
zNodes = eval("(" + data + ")");
},
error: function (data) {
alert(data);
}
});
zTreeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
});
public void ProcessRequest(HttpContext context)
{
if (context.Session["UserInfo"] != null)
{
//ZTree加载
SynchronousJsonTree(context);
}
else
{
context.Response.Write(string.Format(@"window.location.href='{0}'","Logon.aspx"));
}
}
/// <summary>
/// 同步ZTree加载
/// </summary>
/// <param name="context"></param>
private void SynchronousJsonTree(HttpContext context)
{
//
SYS_UserInfo user = context.Session["UserInfo"] as SYS_UserInfo;
List<SYS_Menu> menuList = _iSysMenu.LoadSysMenu(user);
StringBuilder sb = new StringBuilder();
if (menuList.Count > 0)
{
sb.Append("[");
foreach (SYS_Menu li in menuList)
{
sb.Append("{id:" + li.Menuid + ",pId:" + li.ParentId + ",name:"" + li.Menu + "",action:"" + li.Url + """);
sb.Append("},");
}
sb = sb.Remove(sb.Length - 1, 1);
sb.Append("]");
}
string content = sb.ToString();
context.Response.Write(content);
}