后台传JSON

 public class CourseType : IHttpHandler
{
Epoint.PeiXun.Bizlogic.BLL.CourseLibrary.PX_CourseType.B_PX_CourseType b_coursetype = new Epoint.PeiXun.Bizlogic.BLL.CourseLibrary.PX_CourseType.B_PX_CourseType(); List<CourseTypeData> list_CourseType = new List<CourseTypeData>();
CourseTypeChartData CourseTypecd = new CourseTypeChartData();
public void ProcessRequest(HttpContext context)
{
string rjson = string.Empty; try
{
int Count1;
string where = "where 1=1";
DataView dv = Epoint.MisBizLogic2.DB.GetData_Page_ByConnName(
"*",
,
,
" PX_CourseType ",//Frame_AttachInfo和NTI_CourseChapter
"Row_ID",
where,
"ParentRowID asc,OrderNum desc",
out Count1,
"DJG_PeiXun_ConnectionString"
).DefaultView;
CourseTypecd.PicNum = Convert.ToString(dv.Count);
for (int i = ; i < dv.Count; i++)
{
list_CourseType.Add(new CourseTypeData(Convert.ToString(dv[i]["TypeName"].ToString()), Convert.ToString(dv[i]["parentRowID"].ToString()), Convert.ToString(dv[i]["Row_ID"].ToString())));
}
CourseTypecd.CourseData = list_CourseType;
rjson = new Epoint.KSPXBase.Bizlogic.DB_Common().Obj2Json(CourseTypecd); }
catch
{
rjson = "";
} context.Response.ContentType = "text/plain";
context.Response.Write(rjson);//返回调用处
} public bool IsReusable
{
get
{
return false;
}
} internal class CourseTypeData
{
public CourseTypeData(string typeName, string parentRowID,string row_id)
{
TypeName = typeName;//类别名称
ParentRowID = parentRowID;
Row_ID = row_id;
}
public string TypeName;
public string ParentRowID;
public string Row_ID;
} internal class CourseTypeChartData
{
public string PicNum;//数据个数
public List<CourseTypeData> CourseData;
}
}

前台解析,并拼接显示

 $(function () {//加载课程推荐
LoadCourseTypeName($("#CourseType"));//加载课程
}); function LoadCourseTypeName(obj) {
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "<%=Request.ApplicationPath%>/Ashx/CourseType.ashx?",
dataType: 'text',
complete: function () { },
beforeSend: function () {
obj.html("<div class='divLoadTips'>课程内容加载中...</div>");
},
success: function (result) {
var res = JSON.parse(result);//得到json值
var rtn = parseInt(res.PicNum);
obj.html("")
var span, a;
for (var i = ; i < rtn; i++) {
var parentRowID = res.CourseData[i].ParentRowID;
if (parentRowID == "") {
var row_id = res.CourseData[i].Row_ID;
var li = $("<li class='drop-menu-item' id='" + row_id + "'> </li>");
span = $("<span class='drop-menu-cate' >" + res.CourseData[i].TypeName + "</span>")
li.append(span);
}
else {
$("#menucourse ul li").each(
function (index) { if ($(this).attr("id") == parentRowID) {
a = $("<a href='#'> " + res.CourseData[i].TypeName + "</a>");
$(this).append(a);
}
}
); } obj.append(li);
}
},
error: function (result, status) {
alert(result.responseJSON.Message);
}
})
}

后台给前台传JSON字符串,前台解析并拼接显示的更多相关文章

  1. Kotlin入门(31)JSON字符串的解析

    json是App进行网络通信最常见的数据交互格式,Android也自带了json格式的处理工具包org.json,该工具包主要提供了JSONObject(json对象)与JSONArray(json数 ...

  2. 动态Json字符串的解析

    动态Json字符串的解析 对于传统的Json字符串,比如有规定属性的对象,通常都会采用反序列化的方式就可以了,例如下面的方式: DataContractJsonSerializer ser = new ...

  3. Retrofit 2.0 超能实践(三),轻松实现文件/多图片上传/Json字符串

    文:http://blog.csdn.net/sk719887916/article/details/51755427 Tamic 简书&csdn同步 通过前两篇姿势的入门 Retrofit ...

  4. Retrofit 2.0 轻松实现多文件/图片上传/Json字符串/表单

    如果嫌麻烦直接可以用我封装好的库:Novate: https://github.com/Tamicer/Novate 通过对Retrofit2.0的前两篇的基础入门和案例实践,掌握了怎么样使用Retr ...

  5. HttpClient 模拟发送Post和Get请求 并用fastjson对返回json字符串数据解析,和HttpClient一些参数方法的deprecated(弃用)的综合总结

    最近在做一个接口调用的时候用到Apache的httpclient时候,发现引入最新版本4.5,DefaultHttpClient等老版本常用的类已经过时了,不推荐使用了:去官网看了一下在4.3之后就抛 ...

  6. 前台给后台传JSON字符串,后台解析并保存

    前台 function BMSure() { var DanWeiName = $("[id$='BusinessName']").val(); var Address = $(& ...

  7. 前台传JSON到后台

    现在,有一个需求,我需要将表格中选中行的数据中的一部分传直接传到控制器中,然后保存到另外一张表中.一开始,我就想到在前台使用ajax构造json数据,然后控制器直接通过list接收. 选中界面中的行, ...

  8. 分享知识-快乐自己:SpringMvc整合遇到-前台传JSON参数,后台实体类对象接收

    前台数据转JSON对象: /** * * @param $myFrom:from表单 * @returns {{}} */ function from($myFrom) { var ebookEntr ...

  9. 后台date类型转换为json字符串时,返回前台页面的是long类型的时间戳问题解决

    学习springboot框架,写个博客系统,在后台管理的日志管理中,遇到了后台查询的日期格式的结果返回到页面变成了日期的时间戳了.然后摸索了三种方法来解决.页面的显示问题如下图. 问题页面回顾: 本案 ...

随机推荐

  1. python datetime处理时间

    原文:http://blog.csdn.net/JGood/article/details/5457284 Python提供了多个内置模块用于操作日期时间,像calendar,time,datetim ...

  2. 怎么将Android studio 的“ build:gradle改低一点”

    参考来源:http://bbs.qcloud.com/thread-17193-1-1.html Error:Execution failed for task ':xxxx:compileDebug ...

  3. CSS-position详解

    position属性 position属性可以调整DOM元素在浏览器中的位置,能够很好的体现HTML普通流这个特征.重点在于应用了不同的position值之后是否有脱离普通流和改变Display属性这 ...

  4. angular初步认识一

    最近比较流行MVC前端框架开发,最近研究了一个框架AngularJS框架 不说那么多,先上例子,我是个代码控 <!DOCTYPE html> <html lang="en& ...

  5. java通用的方法整理

    判断字符串是否为空 public static boolean IsEmpty(String str){ if (str == null){ return true; } if ("&quo ...

  6. StoryBoard解惑

    可以把StoryBoard看做是一组viewController对应的xib,以及它们之间的转换方式的集合.在StoryBoard中不仅可以看到 每个ViewController的布局样式,也可以明确 ...

  7. python时间时分秒与秒数的互相转换

    受到Unix时间戳的启发,我发现时间转成秒数后会非常好处理,在程序当中不再是以字符串的形式处理,不管时间的加减还是获取随机的时间点都变得非常方便, 如果有需要,也很容易转换成需要的时间格式. 一:时间 ...

  8. python3下载远程代码并执行

    第一步: 先在gist之类的网站上贴上代码,目的不是高亮,而可以raw的形式获取代码,这样可以省掉处理html的时间,我这里用的是pasteraw: 远程上的代码:http://cdn.pastera ...

  9. @font-face 的用法

    现在很多设计用的字体都是五花八门的.我们切图又不能很好的让搜索爬虫搜索.就会使用@font-face方法: @Font-face目前浏览器的兼容性: Webkit/Safari(3.2+):TrueT ...

  10. Android数据持久化技术 — — —SharedPreferences

    SharedPreferences是使用键值对的方式来存储数据. 要想使用SharedPreferences来存储数据,必须获取SharedPreferences对象,获取SharedPreferen ...