.net里ajax调用后台方法返回LIST集合

JS部分

function GetPageInfo() {
            var loadid = layer.load(1, { shade: 0.1 });
            var url = "ReservePlanTotal.aspx?act=GetTotal";
            var search_date = $("#search_date").val();
            var DepartmentClassID = $(".DepartmentClassID").val();
            var groupName = $(".GroupID option:selected").text();
            $(".dateTitle").text(search_date);
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: { search_date: search_date, groupName: groupName, DepartmentClassID: DepartmentClassID },
                success: function (r) {
                    try {
                        //alert(JSON.stringify(r));
                        console.log(r);
                        //debugger;
                        if (r.code == 200) {
                            $(".tbody").html(r.list);
                        }
                        else {
                            layer.msg(r.ErrorMsg, { icon: 5 });
                            layer.close(loadid);
                        }
                    } catch (e) {
                        layer.close(loadid);
                    }
                }, complete: function (r) {
                    layer.close(loadid);
                }
            });
        }

HTML部分

                   
                   
                

后台方法部分

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckLoginInfo();//检查登录
                if (!string.IsNullOrEmpty(Request["act"]))
                {
                    act = Request.QueryString["act"];
                }
                switch (act)
                {
                    case "GetTotal":
                        GetTotal();
                        break;
                    default:
                        
                        break;
                }
                PageLoad();
            }
            
        }

private void GetTotal()
        {
            ResultInfo resultInfo = new ResultInfo() { State = false };
            StringBuilder sb = new StringBuilder();
            try
            {
                string search_date = Request["search_date"];
                string DepartmentClassID = Request["DepartmentClassID"];//院区
                string groupName = Request["groupName"];//分诊组
                string searchStr = " and leibie=1 and [SickID] =0 and zhenshi<>'协同诊疗' ";
                if (!string.IsNullOrEmpty(groupName))
                {
                    if (groupName!= "全部治疗组")
                    {
                        searchStr += " and zhenshi='" + groupName + "'";
                    }
                    
                }
                if (!string.IsNullOrEmpty(DepartmentClassID))
                {
                    if (DepartmentClassID != "0")
                    {
                        searchStr += " and zhenshi in(select groupName from MyMedicalGroup where ID=" + DepartmentClassID + " )";
                    }
                    
                }
                if (!string.IsNullOrEmpty(search_date))
                {
                    DateTime startDate = Convert.ToDateTime(search_date.Trim(' ').Split('到')[0]);
                    DateTime endDate = Convert.ToDateTime(search_date.Trim(' ').Split('到')[1]);
                    searchStr += " and t>='"+ startDate + "' and t<'"+ endDate + "'";
                }
                List list = myPlanBLL.GetList02(searchStr);
                sb.Append("预约来诊数据");
                if (list!=null)
                {
                    sb.Append("科室预约病人数量已来诊病人数未来诊病人数");
                    foreach (MyWeb.Model.MyPlanTongJi model in list)
                    {
                        sb.Append("" + model.Zhenshi + "" + model.YuyueNum + "" + model.YilaizhenNum + "" + model.WeilaizhenNum + "");
                    }
                }
                else
                {
                    sb.Append("暂无数据");
                }
                //int allNum= myPlanBLL.GetRecordCount(searchStr + " and status!='已完成' ");//
                //int comeingNum = myPlanBLL.GetRecordCount(searchStr+" and status='已来诊' ");//记录总数
                //int noComeingNum = myPlanBLL.GetRecordCount(searchStr + " and status<>'已来诊' " );//记录总数
                
                resultInfo.Data = sb.ToString();
                resultInfo.State = true;
            }
            catch (Exception ex)
            {

                resultInfo.State = false;
                resultInfo.ErrorMsg = ex.Message;
            }
            var rsp_obj = new
            {
                code = 200,
                list = sb.ToString()
            };
            Response.Write(JsonConvert.SerializeObject(rsp_obj));//将rsp_obj转化为json并输出
            Response.End();
            //string resultJson = JsonHelper.ObjectToJSON(resultInfo);
            //Response.Write(resultJson);
            //Response.End();
        }

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(asp.net)