.net ajax和后台数据简单交互。传参JSON返回

前台页面部分 

<tbody class="tbody">
                </tbody>

JS部分 

function GetPageInfo() {
            var loadid = layer.load(1, { shade: 0.1 });
            var url = "ReservePlanTotal.aspx?act=GetTotal";
            var search_date = $("#search_date").val();//
            var areaID = $(".selArea").val();
            var typeID = $(".selType").val();
            var groupID = $(".selGroup").val();
            var need = $(".need").val();

            $(".dateTitle").text(search_date);
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: { search_date: search_date, areaID: areaID, typeID: typeID, groupID: groupID, need: need },
                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);
                }
            });
        }

后台部分

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()
        {
            StringBuilder sb = new StringBuilder();
            string search_date = Request["search_date"];
            string areaID = Request["areaID"];//院区ID
            string typeID = Request["typeID"];//分组类别
            string groupID = Request["groupID"];//分组ID
            string need = Request["need"];//来诊目的
            string searchStr = " and leibie=1 and [SickID] =0 and zhenshi<>'协同诊疗' ";
            string searchStr02 = " ";
            if (areaID != "0")
            {
                searchStr02 += " and areaID=" + areaID + " ";
            }
            if (typeID != "0")
            {
                searchStr02 += " and typeID=" + typeID + " ";
            }
            if (groupID != "0")
            {
                searchStr02 += " and groupID=" + groupID + " ";
            }
            if (need != "")
            {
                searchStr += " and need=" + need + " ";
            }
            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<MyWeb.Model.MyPlanTongJi> list = myPlanBLL.GetList02(searchStr, searchStr02);
            sb.Append("<tr><td colspan=\"7\" style=\"text-align:center; \"><span class=\"dateTitle\"></span>预约来诊数据</td></tr>");
            if (list != null)
            {
                sb.Append("<tr><td>院区</td><td>组类别</td><td>分组名称</td><td>预约病人数量</td><td>已来诊病人数</td><td>未来诊病人数</td><td>完成病人数</td></tr>");
                for (int i = 0; i < list.Count; i++)
                {
                    sb.Append("<tr><td>" + list[i].AreaName + "</td><td>" + list[i].TypeName + "</td><td>" + list[i].GroupName + "</td><td class=\"showDetails\" onclick=\"showDetailsClick(this)\" GroupID=\"" + list[i].GroupID + "\" status=\"\" search_date=\"\">" + list[i].YuyueNum + "</td><td class=\"showDetails\" onclick=\"showDetailsClick(this)\" GroupID=\"" + list[i].GroupID + "\" status=\"已来诊\">" + list[i].YilaizhenNum + "</td><td class=\"showDetails\" onclick=\"showDetailsClick(this)\" GroupID=\"" + list[i].GroupID + "\" status=\"未来诊\">" + list[i].WeilaizhenNum + "</td><td class=\"showDetails\" onclick=\"showDetailsClick(this)\" GroupID=\"" + list[i].GroupID + "\" status=\"完成\">" + list[i].WanchengNum + "</td></tr>");
                }
            }
            else
            {
                sb.Append("<tr><td colspan=\"7\" style=\"text-align:center; \"><span class=\"dateTitle\"></span>暂无数据</td></tr>");
            }
            var rsp_obj = new
            {
                code = 200,
                list = sb.ToString()
            };
            Response.Write(JsonConvert.SerializeObject(rsp_obj));//将rsp_obj转化为json并输出
            Response.End();
        }

 

 

 

posted @ 2020-06-11 08:46  离。  阅读(58)  评论(0编辑  收藏