先贴代码

 function edit(node) {
var customerid = $(node).parents("tr").children().eq().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[]["buttid"] + "buttname " + butt[]["buttname"] + "butt_tel " + butt[]["butt_tel"] + "accountname: " + butt[]["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 = ; 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");
} }


第一点:正是上面所说,因为没有写接受数据类型(dataType:json),导致我接收的返回数据是字符串类型。
然后:(导致我怀疑人生—)?? 凭啥我的each 遍历不了数据(实在搞不了,只有将接收到的res 通过eval()封装成变量)
第二点:很让我惊喜的是,后台返回的数据(它是一个对象)居然可以通过 “.” 来访问,很骚啊!哥,我传过来的是一个数组,
里面封装的是对象,还以为只能通过butt["buttid"] 来访问。实在没必要。

 

前端 ajax 获取后台json数据 解析的更多相关文章

  1. 原生js,jquery通过ajax获得后台json数据动态新增页面元素

    一.原生js通过ajax获取json数据 因为IE浏览器对ajax对象的创建和其他浏览器不同,为了兼容全部浏览器,我用下面的代码: function createXMLHttpRequest(){ t ...

  2. jq获取后台json并解析

    参考: $(function () { $.ajax({ url: 'tsconfig.json', type: 'GET', dataType: 'json', timeout: 1000, cac ...

  3. Jquery Ajax和getJSON获取后台普通Json数据和层级Json数据解析

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

  4. java后台设计简单的json数据接口,设置可跨域访问,前端ajax获取json数据

    在开发的过程中,有时候我们需要设计一个数据接口.有时候呢,数据接口和Web服务器又不在一起,所以就有跨域访问的问题. 第一步:简单的设计一个数据接口. 数据接口,听起来高大上,其实呢就是一个简单的Se ...

  5. jQuery AJAX获取JSON数据解析多种方式示例

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

  6. 用ajax获取后台数据,返回json数据,怎么在前台使用?

    用ajax获取后台数据,返回json数据,怎么在前台使用呢?后台 C# code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 if (dataType == &qu ...

  7. 使用ajax解析后台json数据时:Unexpected token o in JSON at position 1

    json数据解析异常 今天在做json数据的时候,出现了如下错误,说是解析异常. VM1584:1 Uncaught SyntaxError: Unexpected token o in JSON a ...

  8. 使用@RequestBody注解获取Ajax提交的json数据

    最近在学习有关springMVC的知识,今天学习如何使用@RequestBody注解来获取Ajax提交的json数据内容. Ajax部分代码如下: 1 $(function(){ 2 $(" ...

  9. 前端学习——使用Ajax方式POST JSON数据包

    0.前言     本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...

随机推荐

  1. JS:事件委托

    事件委托 事件流 事件流描述的是从页面中接收事件的顺序.---JS高级程序设计(第3版) DOM Level 2 Events规定的事件流有三个阶段:①事件捕获阶段.②处于目标阶段.③事件冒泡阶段 事 ...

  2. 如何在window server IIS上部署可以使用web deploy?

    环境: windows server2012 方式1: 1,下载"wpilauncher.exe" Web平台安装程序.下载地址:http://www.microsoft.com/ ...

  3. 【数组】Search Insert Position

    题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...

  4. Chapter 3 Phenomenon——14

    They wheeled me away then, to X-ray my head. 他们把我移到了一边用X光照射我的头. 他们把我放到轮椅上,推着我去做头部X光检查. I told them t ...

  5. 微服务Kong(十)——负载均衡参考

    KONG为请求多个后端服务提供了多种负载均衡方案:一种是简单的基于DNS,另一种是更加动态的环形均衡器,他在不需要DNS服务器的情况下也允许服务注册. 一.基于DNS的负载均衡 当使用基于DNS的负载 ...

  6. PostgreSQL执行超时的问题

    PostgreSQL执行超时的问题 使用背景 最近在使用PostgreSQL的时候,在执行一些数据库事务的时候,先后出现了statement timetout 和idle-in-transaction ...

  7. Git的gitattributes文件详解

    转自:Git的gitattributes文件详解 Git的gitattributes文件是一个文本文件,文件中的一行定义一个路径的若干个属性. 1. gitattributes文件以行为单位设置一个路 ...

  8. Java 国际化

    国际化英文单词为:Internationalization,又称I18N,I为因为单词的第一个字母,18为这个单词的长度,而N代表这个单词的最后一个字母.国际化又称本地化(Localization,L ...

  9. layui框架使用总结

    最近一个后台系统使用layui框架做的,遇到好多坑在这里总结一下. 1.layui的基本使用,下面的在他下面写,其他的事件也要在这个里面写     行内onclick事件是监听不到写在下面这种代码中的 ...

  10. < Python Index >

    1. 基本语法   1.1 常量/变量   1.2 运算符   1.3 表达式   1.4 程序结构 2. 内置数据结构    2.1 列表    2.2 元组    2.3 集合    2.4 st ...