jquery ajax和getjson获取后台普通json数据和层级json数据用法分析

上传人:bin****86 文档编号:59370566 上传时间:2018-11-06 格式:DOCX 页数:11 大小:17.34KB
返回 下载 相关 举报
jquery ajax和getjson获取后台普通json数据和层级json数据用法分析_第1页
第1页 / 共11页
jquery ajax和getjson获取后台普通json数据和层级json数据用法分析_第2页
第2页 / 共11页
jquery ajax和getjson获取后台普通json数据和层级json数据用法分析_第3页
第3页 / 共11页
jquery ajax和getjson获取后台普通json数据和层级json数据用法分析_第4页
第4页 / 共11页
jquery ajax和getjson获取后台普通json数据和层级json数据用法分析_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《jquery ajax和getjson获取后台普通json数据和层级json数据用法分析》由会员分享,可在线阅读,更多相关《jquery ajax和getjson获取后台普通json数据和层级json数据用法分析(11页珍藏版)》请在金锄头文库上搜索。

1、我真正系统地接触和学习党的基本知识是在这次中级党校的培训班上。通过学习,了解了党的发展历程,对党的性质、宗旨、任务等基本知识有了进一步的了解jQuery Ajax和getJSON获取后台普通json数据和层级json数据用法分析本文实例讲述了jQuery Ajax和getJSON获取后台普通json数据和层级json数据用法。分享给大家供大家参考,具体如下:运行效果截图如下:代码如下:http:/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd Ajax和getJSON获取后台普通Json数据和层级Json数据解析 $(function () /

2、方式一 Ajax方式获取Json数据 $.ajax( url: jsondata.ashx?type=1, type: GET, dataType: json, timeout: 1000, cache: false, beforeSend: LoadFunction, /加载执行方法 error: erryFunction, /错误执行方法 success: succFunction /成功执行方法 ) function LoadFunction() $(#list).html(加载中.); function erryFunction() alert(error); function suc

3、cFunction(tt) var json = eval(tt); /数组 var tt = ; $.each(json, function (index) /循环获取数据 var Id = jsonindex.id; var Name = jsonindex.name; var Age = jsonindex.age; var Score = jsonindex.score; tt += Id + _ + Name + _ + Age + _ + Score + ; ); $(#list).html(); $(#list).html(tt); /方式二 Json方式获取数据 $.getJS

4、ON( jsondata.ashx?type=1, function (data) /循环获取数据 var tt = ; $.each(data, function (k, v) $.each(v, function (kk, vv) tt += kk + : + vv + _; ); tt += ; ); $(#list2).html(tt); ); /方式三 Ajax方式获取Json层级数据 $.ajax( url: jsondata.ashx?type=3, type: GET, dataType: json, timeout: 1000, cache: false, beforeSen

5、d: LoadFunction1, /加载执行方法 error: erryFunction1, /错误执行方法 success: succFunction1 /成功执行方法 ) function LoadFunction1() $(#list3).html(加载中.); function erryFunction1() alert(error); function succFunction1(tt) var json = eval(tt); /数组 var tt = ; $.each(json, function (index) /循环获取数据 var Id = jsonindex.id; v

6、ar Name = jsonindex.name; var Age = jsonindex.age; var Score = jsonindex.score; tt += Id + _ + Name + _ + Age + _; $.each(Score, function (k, v) tt += k + : + v + _; ) tt += ; ); $(#list3).html(); $(#list3).html(tt); /方式四 Json方式获取层级数据 $.getJSON( jsondata.ashx?type=3, function (json) /循环获取数据 var tt =

7、 ; $.each(json, function (index) /循环获取数据 var Id = jsonindex.id; var Name = jsonindex.name; var Age = jsonindex.age; var Score = jsonindex.score; tt += Id + _ + Name + _ + Age + _; $.each(Score, function (k, v) tt += k + : + v + _; ) tt += ; ); $(#list4).html(); $(#list4).html(tt); ); ); 方式一 _ 方式二 _

8、方式三 _ 方式四代码如下:using System;using System.Web;using System.Web.Script.Serialization;using System.IO;using System.Text;using System.Collections;using System.Collections.Generic;using System.Data;using Newtonsoft.Json;public class jsondata : IHttpHandler public void ProcessRequest(HttpContext context) c

9、ontext.Response.ContentType = text/plain; context.Response.Cache.SetNoStore(); string type = context.Requesttype; if (type=1) /普通数据 List aa = new List(); for (int i = 0; i Dictionary aaa = new Dictionary(); aaa.Add(id, no + i); aaa.Add(name, 张三 + i); aaa.Add(age, 21); aaa.Add(score, 1001); aa.Add(aaa); string json = JsonConvert.SerializeObject(aa, Formatting.Indented); context.Response.Write(json); if (type = 3) /层级数据 List list = new List(); for (int i = 0; i Student a = new Student(); a.id = no + i; a.name = 张三 + i; a.age = 21;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 总结/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号