<script type="text/javascript">
$.ajax({
type: "post",
url: "HandlerDeptData.ashx",
dataType: "json",
async: false,
data:"method=GetDeptData",
success: function (jsonData) {
var json = eval(jsonData);
for (var i = 0; i < json.length; i++) {
$("#cboDeptName").append("<option value=" + json[i].deptId + ">" + json[i].deptName + "</option>");
}
}
});
</script>
<%@ WebHandler Language="C#" Class="HandlerDeptData" %>
using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Web.Script.Serialization;
using Entity;
public class HandlerDeptData : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/json";
string method = context.Request.Params["method"].ToString();
switch(method)
{
case "GetDeptData":
GetDeptData(context);
break;
}
}
public bool IsReusable {
get {
return false;
}
}
private void GetDeptData(HttpContext context)
{
List<SysDept> lstDepts = BLL.BllSysDept.GetAllList();
if (lstDepts != null)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
var jsonData = serializer.Serialize(lstDepts);
context.Response.Write(jsonData.ToString());
}
}
}