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. }

ajax 请求 对json传的处理 Jquery 使用Ajax获取后台返回的Json数据后,页面处理的更多相关文章

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

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

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

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

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

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

  4. H5 FormData对象的使用——进行Ajax请求并上传文件

    XMLHttpRequest Level2 添加了一个新的接口——FormData .[ 主要用于发送表单数据,但也可以独立使用于传输键控数据.与普通的Ajax相比,它能异步上传二进制文件 ] 利用F ...

  5. 【前台 ajax】前台ajax请求,地址正确,但是报错不进入后台

    前台ajax请求,地址正确,但是报错不进入后台 出现上述问题,可能的情况是 1.ajax用的post,而后台限定用get,或者所有的post请求都被拦截,所以不能正常进入并且报错403 @Reques ...

  6. js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可)

    js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可) 一.总结 ajax读取json和读取普通文本,和获 ...

  7. 使用form表单提交请求如何获取后台返回的数据?

    问题描述 一般的form表单提交是单向的:只能给服务器发送数据,但是无法获取服务器返回的数据,也就是无法读取HTTP应答包. 想要真正的半双工通讯一般需要使用Ajax, 但是Ajax对文件传输也很麻烦 ...

  8. js循环处理后台返回的json数组

    <script type="text/javascript"> function gongdan_search(elm){ var dangqian_value=$(e ...

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

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

随机推荐

  1. PHP-----数组和常见排序算法

    数组的创建 <?php //php创建数组 //第一种方法 $arr[0]=1; $arr[1]=23; $arr[2]=20; $arr[3]=43; for($i=0;$i<count ...

  2. iOS - Mac Apache WebDav 服务器配置

    前言 Apache 服务器: Web 服务器,可以支持各种脚本(PHP)的执行,目前世界上使用最为广泛的一种 Web 服务器 WebDav 服务器: 基于 http 协议的 "文件" ...

  3. jsonp 跨域 能返回数据但 无法返回成功问题

    apihandler.ashx?callback=eqfeed_callback:1Uncaught SyntaxError: Unexpected token : 原因在于jsonp传的数据格式不一 ...

  4. Android性能优化篇

    很多App都会遇到以下几个常见的性能问题: 启动速度慢:界面跳转慢:事件响应慢:滑动和动画卡顿. 一.启动速度优化. 优化初始化任务: 1. 把一些初始化任务懒加载初始化 2. 把初始化任务并行化(异 ...

  5. Mac 安装mysql

    下载mysql-5.7.14-osx10.11-x86_64.tar # 移动解压后的二进制包到安装目录 sudo mv mysql-5.6.24-osx10.9-x86_64 /usr/local/ ...

  6. Android权限声明

    1.网络 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/ > < ...

  7. cocos2d-x lua绑定解析

    花了几天时间看了下cocos2d-x lua绑定那块,总算是基本搞明白了,下面分三部分解析lua绑定: 一.lua绑定主要用到的底层函数 lua绑定其本质就是有一个公用的lua_Stack来进行C和L ...

  8. VB6.0对鼠标滚轮不支持的解决方法[转]已经测试work

    今天要修改一个老DLL文件,安装了vb6,用起来很不爽. VB6编辑器 和 VBA编辑器 (Office 中的VB编辑器)都不支持鼠标滚动. 但 MS 已经提供了补丁http://download.m ...

  9. C++ | boost库 类的序列化

    是的,这是今年的情人节,一篇还在研究怎么用的文章,文结的时候应该就用成功了. 恩,要有信心 神奇的分割线 不知何时装过boost库的header-only库, 所以ratslam中的boost是可以编 ...

  10. BZOJ2095 [Poi2010]Bridges

    首先二分答案...然后这张图变成了有一些有向边,有一些无向边 然后就是混合图欧拉回路的判断 我们知道如果是有向图,它存在欧拉回路的等价条件是所有点的出度等于入度 对于混合图...先不管有向边,把无向边 ...