zoukankan      html  css  js  c++  java
  • 后台给前台传JSON字符串,前台解析并拼接显示

    后台传JSON

     1 public class CourseType : IHttpHandler
     2     {
     3         Epoint.PeiXun.Bizlogic.BLL.CourseLibrary.PX_CourseType.B_PX_CourseType b_coursetype = new Epoint.PeiXun.Bizlogic.BLL.CourseLibrary.PX_CourseType.B_PX_CourseType();
     4 
     5         List<CourseTypeData> list_CourseType = new List<CourseTypeData>();
     6         CourseTypeChartData CourseTypecd = new CourseTypeChartData();
     7         public void ProcessRequest(HttpContext context)
     8         {
     9             string rjson = string.Empty;
    10 
    11             try
    12             {
    13                 int Count1;
    14                 string where = "where 1=1";
    15                 DataView dv = Epoint.MisBizLogic2.DB.GetData_Page_ByConnName(
    16                    "*",
    17                    100,
    18                    1,
    19                    " PX_CourseType ",//Frame_AttachInfo和NTI_CourseChapter
    20                    "Row_ID",
    21                    where,
    22                    "ParentRowID asc,OrderNum desc",
    23                    out Count1,
    24                    "DJG_PeiXun_ConnectionString"
    25                    ).DefaultView;
    26                 CourseTypecd.PicNum = Convert.ToString(dv.Count);
    27                 for (int i = 0; i < dv.Count; i++)
    28                 {
    29                     list_CourseType.Add(new CourseTypeData(Convert.ToString(dv[i]["TypeName"].ToString()), Convert.ToString(dv[i]["parentRowID"].ToString()), Convert.ToString(dv[i]["Row_ID"].ToString())));
    30                 }
    31                 CourseTypecd.CourseData = list_CourseType;
    32                 rjson = new Epoint.KSPXBase.Bizlogic.DB_Common().Obj2Json(CourseTypecd);
    33 
    34             }
    35             catch
    36             {
    37                 rjson = "0";
    38             }
    39 
    40             context.Response.ContentType = "text/plain";
    41             context.Response.Write(rjson);//返回调用处
    42         }
    43 
    44         public bool IsReusable
    45         {
    46             get
    47             {
    48                 return false;
    49             }
    50         }
    51 
    52         internal class CourseTypeData
    53         {
    54             public CourseTypeData(string typeName, string parentRowID,string row_id)
    55             {
    56                 TypeName = typeName;//类别名称
    57                 ParentRowID = parentRowID;
    58                 Row_ID = row_id;
    59             }
    60             public string TypeName;
    61             public string ParentRowID;
    62             public string Row_ID;
    63         }
    64 
    65 
    66         internal class CourseTypeChartData
    67         {
    68             public string PicNum;//数据个数
    69             public List<CourseTypeData> CourseData;
    70         }
    71     }
    View Code

    前台解析,并拼接显示

     1 $(function () {//加载课程推荐
     2         LoadCourseTypeName($("#CourseType"));//加载课程
     3     });
     4 
     5     function LoadCourseTypeName(obj) {
     6         $.ajax({
     7             type: "POST",
     8             contentType: "application/json;charset=utf-8",
     9             url: "<%=Request.ApplicationPath%>/Ashx/CourseType.ashx?",
    10             dataType: 'text',
    11             complete: function () { },
    12             beforeSend: function () {
    13                 obj.html("<div class='divLoadTips'>课程内容加载中...</div>");
    14             },
    15             success: function (result) {
    16                 var res = JSON.parse(result);//得到json值
    17                 var rtn = parseInt(res.PicNum);
    18                 obj.html("")
    19                 var span, a;
    20                 for (var i = 0; i < rtn; i++) {
    21                     var parentRowID = res.CourseData[i].ParentRowID;
    22                     if (parentRowID == "0") {
    23                         var row_id = res.CourseData[i].Row_ID;
    24                         var li = $("<li class='drop-menu-item' id='" + row_id + "'> </li>");
    25                         span = $("<span class='drop-menu-cate' >" + res.CourseData[i].TypeName + "</span>")
    26                         li.append(span);
    27                     }
    28                     else {
    29                         $("#menucourse ul li").each(
    30                             function (index) {
    31 
    32                                 if ($(this).attr("id") == parentRowID) {
    33                                     a = $("<a href='#'> " + res.CourseData[i].TypeName + "</a>");
    34                                     $(this).append(a);
    35                                 }
    36                             }
    37                             );
    38  
    39                     }
    40 
    41                     obj.append(li);
    42                 }
    43             },
    44             error: function (result, status) {
    45                 alert(result.responseJSON.Message);
    46             }
    47         })
    48     }
    View Code
  • 相关阅读:
    Mycat分布式数据库&.NET链接mysql
    MySQL安装
    Apache 安装配置及开启PHP模块支持
    XSS MSMQ FASTDFS RABBITMQ
    json表单回填(表单反序列化回填值)
    解决80端口被占用
    Oracle for .net & ServiceStack.OrmLite
    MBTiles 离线地图演示
    Java网络编程TCP程序,服务器和客户机交互流程以及基本操作步骤。
    如何使用和理解java的反射机制
  • 原文地址:https://www.cnblogs.com/lyhsblog/p/5966174.html
Copyright © 2011-2022 走看看