加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax解析josn

发布时间:2020-12-16 03:33:20 所属栏目:百科 来源:网络整理
导读:A.js //查询一行数据 $("#Btsouso").bind("click",function () { var searchid = $("#txtids").val(); $.ajax({ type: "post", dataType: "json", url: "Mnet.ashx", cache: false, //async: false, data: { operate: "getuserdetails",sid: searchid }, suc

A.js

//查询一行数据

$("#Btsouso").bind("click",function () {
var searchid = $("#txtids").val();
$.ajax({
type: "post",
dataType: "json",
url: "Mnet.ashx",
cache: false,
//async: false,
data: { operate: "getuserdetails",sid: searchid },
success: function (text,textStatus) {
if (text != null) {
$("#results").html("用户名 :" + text.userName + " + 姓名 :" +

text.name + " 地址 :" + text.place + " ");
}
},
complete: function (XMLHttpRequest,textStatus) {
},
error: function (XMLHttpRequest,textStatus,errorThrown) {
//alert(XMLHttpRequest.responseText);
}
});
});


//查询多行数据
$("#btgetmoney").bind("click",
data: { operate: "getManyUser",textStatus) {
if (text != null) {
$.each(text,function (i,item) {
$("#results").append("用户名 :" + item.yhusername + " + 姓名 :

" + item.yhname + " 地址 :" + item.dizhi + "<br> ");
});
}
},errorThrown) {

}
});

});


ashx:

/// <summary>
///
/// </summary>
private void getuserdetails(HttpContext context)
{
var id = Convert.ToInt32(context.Request["sid"]);
CodeModel.BLL.userinfo yhbll = new CodeModel.BLL.userinfo();
CodeModel.Model.userinfo yhModel = new CodeModel.Model.userinfo();
yhModel=yhbll.GetModel(int.Parse(id.ToString()));
context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(yhModel));

}

/// <summary>
///
/// </summary>
private void getMoneyusers(HttpContext context)
{
var id = context.Request["sid"].ToString();
CodeModel.BLL.userinfo yhbll = new CodeModel.BLL.userinfo();
CodeModel.Model.userinfo yhModel = new CodeModel.Model.userinfo();
IList<CodeModel.Model.userinfo> list = yhbll.GetUserList("type='"+id+"'");
if (list.Count > 0)
{
var Json = Newtonsoft.Json.JsonConvert.SerializeObject(list.Select(
t => new
{
yhid = t.id,
yhname = t.name,
yhusername=t.userName,
dizhi = t.place,

}));
context.Response.Write(Json);
}
}
C.SQL

//DataSet转换成List<ProductTypeInfo> public IList <CodeModel.Model.userinfo> GetUserList(string strwhere) { IList<CodeModel.Model.userinfo> yhlist = new List<Model.userinfo>(); CodeModel.BLL.userinfo yh = new BLL.userinfo(); //等待转换的DataSet DataSet ds = yh.GetList(strwhere); //遍历ds中Tables[0]数据 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)//逐行遍历 i 是当前行 { CodeModel.Model.userinfo yhmodel = new Model.userinfo(); yhmodel.id = Convert.ToInt32(ds.Tables[0].Rows[i]["id"]); yhmodel.userName = ds.Tables[0].Rows[i]["userName"].ToString(); yhmodel.name = ds.Tables[0].Rows[i]["name"].ToString(); yhmodel.place = ds.Tables[0].Rows[i]["place"].ToString(); //将对象插入到List中 yhlist.Add(yhmodel); } //返回List return yhlist; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读