.net获取ajax,jQuery+ajax+asp.net获取Json值的方法

本文实例讲述了jQuery+ajax+asp.net获取Json值的方法。分享给大家供大家参考,具体如下:

jQueryAjaxJson取值示例

$(document).ready(function () {

$("#Button1").click(function () {

$.ajax({

url: 'AjaxQuery.aspx',

type: 'GET',

dataType: 'json',

timeout: 1000,

cache: false,

beforeSend: LoadFunction, //加载执行方法

error: erryFunction, //错误执行方法

success: succFunction //成功执行方法

})

function LoadFunction() {

$("#ddd").html('加载中...');

}

function erryFunction() {

alert("error");

}

function succFunction(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() + "
" + name + " - " + age + " - " + sex + "
");

});

}

});

})

//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 topsvalue = $("#tops").attr('value');

if (num_iid != "" && num_iid2 != "") {

$.ajax({

url: 'TabBaoHandler.ashx',

type: 'POST',

data: 'type=3&num_iid=' + num_iid2 + '&tid=' + tid + '&desc=' + desc + '&top_session=' + topsvalue,

dataType: 'text',

timeout: 20000,

cache: false,

//async: false, //同步

beforeSend: LoadFunction, //加载执行方法

error: erryFunction, //错误执行方法

success: succFunction //成功执行方法

})

function LoadFunction() {

showLoad("正在运行中...");

}

function erryFunction() {

$("#contentdiv").html("

error.png%5C%22sorry,提交失败

");

closeLoad();

}

function succFunction(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 list = new List();

Student c = new Student();

c.Name = "张三";

c.Age = 23;

c.Sex = "男";

list.Add(c);

Student cc = new Student();

cc.Name = "李四";

cc.Age = 25;

cc.Sex = "男";

list.Add(cc);

Student ccc = new Student();

ccc.Name = "李玲";

ccc.Age = 25;

ccc.Sex = "女";

list.Add(ccc);

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格式数据在线操作工具供大家免费使用,相信在以后的开发中可以派上用场:

希望本文所述对大家jQuery程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值