.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();
        }

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章