1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title></title>
  5. <script src="JS/jquery-1.8.0.min.js" type="text/javascript"></script>
  6. <script type="text/javascript">
  7. $(function () {
  8. $.ajax({
  9. url: 'jsondata.ashx',
  10. type: 'GET',
  11. dataType: 'json',
  12. timeout: 1000,
  13. cache: false,
  14. beforeSend: LoadFunction, //加载执行方法
  15. error: erryFunction,  //错误执行方法
  16. success: succFunction //成功执行方法
  17. })
  18. function LoadFunction() {
  19. $("#list").html('加载中...');
  20. }
  21. function erryFunction() {
  22. alert("error");
  23. }
  24. function succFunction(tt) {
  25. $("#list").html('');
  26. //eval将字符串转成对象数组
  27. //var json = { "id": "10086", "uname": "zhangsan", "email": "zhangsan@qq.com" };
  28. //json = eval(json);
  29. //alert("===json:id=" + json.id + ",uname=" + json.uname + ",email=" + json.email);
  30. var json = eval(tt); //数组
  31. $.each(json, function (index, item) {
  32. //循环获取数据
  33. var name = json[index].Name;
  34. var idnumber = json[index].IdNumber;
  35. var sex = json[index].Sex;
  36. $("#list").html($("#list").html() + "<br>" + name + " - " + idnumber + " - " + sex + "<br/>");
  37. });
  38. }
  39. });
  40. </script>
  41. </head>
  42. <body>
  43. <ul id="list">
  44. </ul>
  45. </body>
  46. </html>
  1. <%@ WebHandler Language="C#" Class="jsondata" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.Script.Serialization;
  5. using System.IO;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using Newtonsoft.Json;
  9. using System.Data;
  10. public class jsondata : IHttpHandler {
  11. public void ProcessRequest(HttpContext context)
  12. {
  13. context.Response.ContentType = "text/plain";
  14. string JsonStr = JsonConvert.SerializeObject(CreateDT());
  15. context.Response.Write(JsonStr);
  16. context.Response.End();
  17. }
  18. #region 创建测试数据源
  19. //创建DataTable
  20. protected DataTable CreateDT()
  21. {
  22. DataTable tblDatas = new DataTable("Datas");
  23. //序号列
  24. //tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
  25. //tblDatas.Columns[0].AutoIncrement = true;
  26. //tblDatas.Columns[0].AutoIncrementSeed = 1;
  27. //tblDatas.Columns[0].AutoIncrementStep = 1;
  28. //数据列
  29. tblDatas.Columns.Add("IdNumber", Type.GetType("System.String"));
  30. tblDatas.Columns.Add("Name", Type.GetType("System.String"));
  31. tblDatas.Columns.Add("BirthDate", Type.GetType("System.String"));
  32. tblDatas.Columns.Add("Sex", Type.GetType("System.String"));
  33. tblDatas.Columns.Add("Wage", Type.GetType("System.Decimal"));
  34. tblDatas.Columns.Add("Bonus", Type.GetType("System.Decimal"));
  35. //统计列开始
  36. tblDatas.Columns.Add("NeedPay", Type.GetType("System.String"), "Wage+Bonus");
  37. //统计列结束
  38. tblDatas.Columns.Add("Address", Type.GetType("System.String"));
  39. tblDatas.Columns.Add("PostCode", Type.GetType("System.String"));
  40. //设置身份证号码为主键
  41. tblDatas.PrimaryKey = new DataColumn[] { tblDatas.Columns["IdNumber"] };
  42. tblDatas.Rows.Add(new object[] { "43100000000000", "张三", "1982", "0", 3000, 1000, null, "深圳市", "518000" });
  43. tblDatas.Rows.Add(new object[] { "43100000000001", "李四", "1983", "1", 3500, 1200, null, "深圳市", "518000" });
  44. tblDatas.Rows.Add(new object[] { "43100000000002", "王五", "1984", "1", 4000, 1300, null, "深圳市", "518000" });
  45. tblDatas.Rows.Add(new object[] { "43100000000003", "赵六", "1985", "0", 5000, 1400, null, "深圳市", "518000" });
  46. tblDatas.Rows.Add(new object[] { "43100000000004", "牛七", "1986", "1", 6000, 1500, null, "深圳市", "518000" });
  47. return tblDatas;
  48. }
  49. #endregion
  50. public bool IsReusable
  51. {
  52. get
  53. {
  54. return false;
  55. }
  56. }
  57. }
  1. <!--
  2. <script type="text/javascript">
  3. $(function () {
  4. $.ajax({
  5. url: 'jsondata.ashx',
  6. type: 'GET',
  7. dataType: 'json',
  8. timeout: 1000,
  9. cache: false,
  10. beforeSend: LoadFunction, //加载执行方法
  11. error: erryFunction,  //错误执行方法
  12. success: succFunction //成功执行方法
  13. })
  14. function LoadFunction() {
  15. $("#list").html('加载中...');
  16. }
  17. function erryFunction() {
  18. alert("error");
  19. }
  20. function succFunction(tt) {
  21. $("#list").html('');
  22. //eval将字符串转成对象数组
  23. //var json = { "id": "10086", "uname": "zhangsan", "email": "zhangsan@qq.com" };
  24. //json = eval(json);
  25. //alert("===json:id=" + json.id + ",uname=" + json.uname + ",email=" + json.email);
  26. var json = eval(tt); //数组
  27. $.each(json, function (index, item) {
  28. //循环获取数据
  29. var Key = json[index].key;
  30. var Info = json[index].info;
  31. //                 var idnumber = json[index].IdNumber;
  32. //                 var sex = json[index].Sex;
  33. $("#list").html($("#list").html() + "<br>" + Key + "----" + Info.name); //+ " - " + idnumber + " - " + sex + "<br/>");
  34. });
  35. }
  36. });
  37. </script>
  38. -->
  1. <%@ WebHandler Language="C#" Class="jsondata" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.Script.Serialization;
  5. using System.IO;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. public class jsondata : IHttpHandler {
  11. public void ProcessRequest(HttpContext context)
  12. {
  13. context.Response.ContentType = "text/plain";
  14. context.Response.Cache.SetNoStore();
  15. string data = "[{\"key\":\"1\",\"info\":{\"name\":\"222\",\"age\":\"333\",\"sex\":\"444\"}},{\"key\":\"2\",\"info\":{\"name\":\"999\",\"age\":\"000\",\"sex\":\"111\"}}]";
  16. context.Response.Write(new JavaScriptSerializer().Serialize(data));
  17. }
  18. public bool IsReusable
  19. {
  20. get
  21. {
  22. return false;
  23. }
  24. }
  25. }
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test2013.aspx.cs" Inherits="Test2013" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <script src="JS/jquery-1.8.0.min.js" type="text/javascript"></script>
  7. <script type="text/javascript">
  8. function GetPara(o) {
  9. var sortid = $(o).val();
  10. $.ajax({
  11. url: 'GetPara.ashx?type=get&sortid=' + sortid,
  12. type: 'GET',
  13. dataType: 'json',
  14. timeout: 3000,
  15. cache: false,
  16. beforeSend: LoadFunction, //加载执行方法
  17. error: erryFunction,  //错误执行方法
  18. success: succFunction //成功执行方法
  19. })
  20. function LoadFunction() {
  21. $("#list").html('加载中...');
  22. }
  23. function erryFunction() {
  24. alert("error");
  25. }
  26. function succFunction(tt) {
  27. $("#list").html('');
  28. var json = eval(tt); //数组
  29. $.each(json, function (index, item) {
  30. //循环获取数据
  31. var Id = json[index].id;
  32. var Name = json[index].name;
  33. $("#list").html($("#list").html() + "<br>" + Name + "<input type='text' id='" + Id + "' /><br/>");
  34. });
  35. }
  36. };
  37. function SavePara() {
  38. var parameter = {};
  39. $("#list input:text").each(function () {
  40. var key = $(this).attr("id");
  41. var value = $(this).val();
  42. parameter[key] = value;
  43. });
  44. $.ajax({
  45. url: 'GetPara.ashx?type=save',
  46. type: 'POST',
  47. dataType: 'json',
  48. data: parameter,
  49. timeout: 3000,
  50. cache: false,
  51. beforeSend: LoadFunction, //加载执行方法
  52. error: erryFunction,  //错误执行方法
  53. success: succFunction //成功执行方法
  54. })
  55. function LoadFunction() {
  56. }
  57. function erryFunction() {
  58. }
  59. function succFunction(tt) {
  60. }
  61. };
  62. </script>
  63. </head>
  64. <body>
  65. <form id="form1" runat="server">
  66. <div>
  67. <asp:DropDownList ID="ddl1" runat="server" onchange="GetPara(this)">
  68. </asp:DropDownList>
  69. <ul id="list"></ul>
  70. <input type="button" value="保存数据" onclick="SavePara()" />
  71. </div>
  72. </form>
  73. </body>
  74. </html>
  1. <%@ WebHandler Language="C#" Class="GetPara" %>
  2. using System;
  3. using System.Web;
  4. using System.Data;
  5. using System.Collections.Generic;
  6. using System.Web.Script.Serialization;
  7. public class GetPara : IHttpHandler {
  8. public void ProcessRequest (HttpContext context) {
  9. context.Response.ContentType = "text/plain";
  10. string SortId = context.Request["sortid"];
  11. string Type = context.Request["type"];
  12. if (Type=="get")
  13. {
  14. if (!string.IsNullOrEmpty(SortId))
  15. {
  16. DataTable dt = MSCL.SqlHelper.GetDataTable("select * from PR_PRODUCTPARAS where sortid='" + SortId + "' ");
  17. List<Paras> list = new List<Paras>();
  18. for (int i = 0; i < dt.Rows.Count; i++)
  19. {
  20. Paras a = new Paras();
  21. a.id = dt.Rows[i]["PARAID"].ToString();
  22. a.name = dt.Rows[i]["PARANAME"].ToString();
  23. list.Add(a);
  24. }
  25. context.Response.Write(new JavaScriptSerializer().Serialize(list));
  26. }
  27. }
  28. else if (Type == "save")
  29. {
  30. //反序列化json
  31. System.IO.Stream stream = context.Request.InputStream;
  32. System.IO.StreamReader sr = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding("UTF-8"));
  33. string sJson = sr.ReadToEnd();
  34. if (sJson.Contains("&"))
  35. {
  36. string[] sArr = sJson.Split('&');
  37. for (int i = 0; i < sArr.Length; i++)
  38. {
  39. string[] sArr1 = sArr[i].Split('=');
  40. object id = sArr1[0];
  41. object value = sArr1[1];
  42. }
  43. }
  44. }
  45. else
  46. { }
  47. }
  48. public bool IsReusable {
  49. get {
  50. return false;
  51. }
  52. }
  53. public struct Paras
  54. {
  55. public string id;
  56. public string name;
  57. }
  58. }

【转】Jquery 使用Ajax获取后台返回的Json数据后,页面处理的更多相关文章

  1. ajax 请求 对json传的处理 Jquery 使用Ajax获取后台返回的Json数据后,页面处理

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Jquery 使用Ajax获取后台返回的Json数据后,页面处理

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. ajax获取后台传递的json数据

      最近在使用JQuery的ajax方法时,需要返回的数据为json数据,在success返回中数据处理会根据返回方式不同会采用不同的方式来生成json数据.在$.ajax方法中应该是如何来处理的,简 ...

  4. JS获取后台返回的JSON数据

    问题:通过$.get从后台获取了一段json串{"id":"1","name":"ww"},然后要拿到这里面的id和na ...

  5. Ajax处理后台返回的Json数据

    // 处理后台传来的Json字符串装换成Json对象 var dataJson = JSON.parse(data); // 此时可以从Json对象中取值 if(dataJson.result == ...

  6. 【转】Jquery ajax方法解析返回的json数据

    转自http://blog.csdn.net/haiqiao_2010/article/details/12653555 最近在用jQuery的ajax方法传递接收json数据时发现一个问题,那就是返 ...

  7. 前台如何处理后台返回的json数据

    后台返回的json数据格式: { "state": true, "data": { "id": 0, "name": & ...

  8. Struts1.x下使用jquery的Ajax获取后台数据

        jquery中有多种Ajax方法来获取后台数据,我使用的是$.get()方法,具体的理论我不解释太多,要解释也是从别的地方copy过来的.下面就介绍我的项目中的实现方法.     前台页面: ...

  9. jquery序列化form表单使用ajax提交后处理返回的json数据

    1.返回json字符串: /** 将一个字符串输出到浏览器 */ protected void writeJson(String json) { PrintWriter pw = null; try ...

随机推荐

  1. DPAPI机制学习

    0x00 前言 ​绝大多数应用程序都有数据加密保护的需求,存储和保护私密信息最安全的方式就是每次需要加密或解密时都从用户那里得到密码,使用后再丢弃.这种方式每次处理信息时都需要用户输入口令,对于绝大多 ...

  2. Android内核的编译和调试

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/70500488 一.Android内核源码的选择 Android手机设备内核源码的调 ...

  3. Android Studio导入Android 4.4.4r1的源码

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/70339471 一.环境配置 1.ubuntu 14.04.5 x64bit 2.j ...

  4. Shodan的使用

    目录 Shodan Shodan工作原理 Shodan的使用 使用搜索过滤 Kali中安装 Shodan Kali中Shodan的使用 Shodan Shodan 是一个搜索引擎,但它与 Google ...

  5. CVE-2019-11043 Nginx PHP 远程代码执行漏洞复现

    漏洞背景:来自Wallarm的安全研究员Andrew Danau在9月14-16号举办的Real World CTF中,意外的向服务器发送%0a(换行符)时,服务器返回异常信息.由此发现了这个0day ...

  6. Windows PE 第一章开发环境和基本工具使用

    第一章 Windows PE 基本工具 1.1开发语言MASM32 1.1.1设置开发环境 这个不细说了,我在整理Intel汇编的时候详细的说了环境搭建以及细节.地址是:http://blog.csd ...

  7. React-列表 & Key

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...

  8. 0901-生成对抗网络GAN的原理简介

    0901-生成对抗网络GAN的原理简介 目录 一.GAN 概述 二.GAN 的网络结构 三.通过一个举例具体化 GAN 四.GAN 的设计细节 pytorch完整教程目录:https://www.cn ...

  9. 谷歌浏览器安装Vue.js devtools

    第一步:访问谷歌商店 在之前的博客中已经谈到了这一点的实现方式 https://www.cnblogs.com/10134dz/p/13552777.html 第二步:下载Vue.js devtool ...

  10. 基于ray的分布式机器学习(一)

    基本思路:1.对数据分块,使用多个worker分别处理一个数据块,每个worker暴露两个接口,分别是损失计算的接口loss和梯度计算的接口grad:2.同时定义full_loss和full_grad ...