jQuery+ajax+asp.net获取Json值的方法
网络编程 2021-07-04 19:59www.168986.cn编程入门
这篇文章主要介绍了jQuery+ajax+asp.获取Json值的方法,涉及jQuery的ajax技术与asp.后台交互的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了jQuery+ajax+asp.获取Json值的方法。分享给大家供大家参考,具体如下:
<html xmlns="http://.w3./1999/xhtml"> <head> <title>jQueryAjaxJson取值示例</title> <script type="text/javascript" src="Scripts/jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#Button1").click(function () { $.ajax({ url: 'AjaxQuery.aspx', type: 'GET', dataType: 'json', timeout: 1000, cache: false, beforeSend: LoadFunction, //加载执行方法 error: erryFunction, //错误执行方法 suess: suFunction //成功执行方法 }) function LoadFunction() { $("#ddd").html('加载中...'); } function erryFunction() { alert("error"); } function suFunction(tt) { $("#ddd").html(''); var json = eval(tt); //数组 $.each(json, function (index, item) { //循环获取数据 var name = json[index].Name; var age = json[index].Age; var sex = json[index].Sex; $("#ddd").html($("#ddd").html() + "<br>" + name + " - " + age + " - " + sex + "<br/>"); }); } }); }) </script> </head> <body> <input type="button" id="Button1" value="获取json数据" /> <span id="ddd"></span> </body> </html>
//Ajax Post Text function savedata(tempid) { var tid = $('#hidtemplate').attr('value'); var desc = $("#contentdiv").html(); var num_iid = $("#num_iidArr").attr('value'); var num_iid2 = $("#num_iidArr001").attr('value'); //发布页面 var svalue = $("#s").attr('value'); if (num_iid != "" && num_iid2 != "") { $.ajax({ url: 'TabBaoHandler.ashx', type: 'POST', data: 'type=3&num_iid=' + num_iid2 + '&tid=' + tid + '&desc=' + desc + '&_session=' + svalue, dataType: 'text', timeout: 20000, cache: false, //async: false, //同步 beforeSend: LoadFunction, //加载执行方法 error: erryFunction, //错误执行方法 suess: suFunction //成功执行方法 }) function LoadFunction() { showLoad("正在运行中..."); } function erryFunction() { $("#contentdiv").html("<p style=\"padding:5px\"><img src=\"images/error.png\" />sorry,提交失败</p>"); closeLoad(); } function suFunction(tt) { closeLoad(); $("#contentdiv").show().html(tt); } } else { alert("请选择后再操作"); } }
using System; //新增 using System.Web.Script.Serialization; using System.Collections.Generic; public partial class AjaxQuery : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Student> list = new List<Student>(); Student c = new Student(); c.Name = "张三"; c.Age = 23; c.Sex = "男"; list.Add(c); Student = new Student(); .Name = "李四"; .Age = 25; .Sex = "男"; list.Add(); Student c = new Student(); c.Name = "李玲"; c.Age = 25; c.Sex = "女"; list.Add(c); Response.ContentType = "application/json"; Response.Write(new JavaScriptSerializer().Serialize(list));////这个很关键,否则error Response.End(); } } public struct Student { public string Name; public int Age; public string Sex; } }
PS:这里推荐几款本站的json格式数据在线操作工具供大家免费使用,相信在以后的开发中可以派上用场:
在线JSON代码检验、检验、美化、格式化工具:
在线XML/JSON互相转换工具:
C语言风格/HTML/CSS/json代码格式化美化工具:
json代码在线格式化/美化/压缩/编辑/转换工具:
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程