前端 ajax 获取后台json数据 解析
发布时间:2020-12-16 03:02:46 所属栏目:百科 来源:网络整理
导读:先贴代码 function edit(node) { var customerid = $(node).parents( " tr " ).children().eq( 0 ).text(); alert(customerid) $.ajax({ type: " post " ,url: " /IsCreateCoustomer/AddButtes?id= " + customerid,// dataType: " json " ,//这个数据传输格
先贴代码 function edit(node) { var customerid = $(node).parents("tr").children().eq(0).text(); alert(customerid) $.ajax({ type: "post",url: "/IsCreateCoustomer/AddButtes?id=" + customerid,// dataType: "json",//这个数据传输格式一开始我是没写的,因为没意识到她的用处,以为传数据有用,接数据没用,真是无知 success: function (res) { if (res != "nobutt") { var butt = eval(res);//这个可以将字符串转化为变量对象 console.log("buttid 0" + butt[0]["buttid"] + "buttname " + butt[0]["buttname"] + "butt_tel " + butt[0]["butt_tel"] + "accountname: " + butt[0]["accountname"]); //for(k=0;k < butt.length;k++){ // console.log("buttid kk " + butt[k]["buttid"] +" ggg"+ butt[k].buttid+ "buttname " + butt[k].buttname + "butt_tel " + butt[k]["butt_tel"] + "accountname: " + butt[k]["accountname"]); //} $.each(res,function (i,butt) { // console.log(" each buttid " + butt["buttid"] + "buttname " + butt["buttname"] + "butt_tel " + butt["butt_tel"] + "accountname: " + butt["accountname"]) console.log("索引 :" + i) console.log("butt :" + butt.buttname) }) //$.each(function (i,butt) { // console.log(butt[i]) // console.log("buttid " + butt[i]["buttid"] + "buttname " + butt[i]["buttname"] + "butt_tel " + butt[i]["butt_tel"] + "accountname: " + butt[i]["accountname"]) //}) } else { alert("!!!") } } }) $("#model").modal(‘show‘); $("#edit").attr("src","/IsCreateCoustomer/AddCoustomer?oper=update&&id=" + customerid); $(".modal-title").append("编辑"); $("#edit").load(); } //后端代码 [HttpPost] public ActionResult AddButtes(int id) { bool s = (new ButtDAO().GetCoustButtList().SingleOrDefault().coustomerid == id); if (s) { List<CoustomerButtInfo> CoustomerButtList = new ButtDAO().GetCoustomerButtList(e => e.coustomerid == id).ToList(); List<buttinfo> buttList = new List<buttinfo>(); for (int i = 0; i < CoustomerButtList.Count; i++) { buttList.Add(new ButtDAO().GetModelList(e => e.buttid == CoustomerButtList[i].buttid).FirstOrDefault()); } string result = JsonConvert.SerializeObject(buttList); return Content(result); } else { //无对接人 return Content("nobutt"); } }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |