先贴代码

 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. 课程一(Neural Networks and Deep Learning),第一周(Introduction to Deep Learning)—— 1、经常提及的问题

    Frequently Asked Questions Congratulations to be part of the first class of the Deep Learning Specia ...

  2. C51单片机中data、idata、xdata、pdata的区别

    C51单片机中data.idata.xdata.pdata的区别 data: 固定指前面0x00-0x7f的128个RAM,可以用acc直接读写的,速度最快,生成的代码也最小. idata: 固定指前 ...

  3. springboot-mongodb的多数据源配置

    pom.xml中引入mongodb的依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...

  4. equal&==&hashcode

    == 和 equals 的区别 Object类中的equals方法和“==”是一样的,没有区别,而String类,Integer类等等一些类,是重写了equals方法,才使得equals和“==不同” ...

  5. [心平气和读经典]The TCP/IP Guide(005)

    The TCP/IP Guide[Page 47, 48, 49] I created The TCP/IP Guide to provide you with an unparalleled bre ...

  6. redis集群与分片(1)-redis服务器集群、客户端分片

    下面是来自知乎大神的一段说明,个人觉得非常清晰,就收藏了. 为什么集群? 通常,为了提高网站响应速度,总是把热点数据保存在内存中而不是直接从后端数据库中读取.Redis是一个很好的Cache工具.大型 ...

  7. redis实战笔记(8)-第8章 构建简单的社交网站

    本章主要内容   用户和状态 主页时间线 关注者列表和正在关注列表 状态消息的发布与删除 流API                  

  8. Spring中使用两种Aware接口自定义获取bean

    在使用spring编程时,常常会遇到想根据bean的名称来获取相应的bean对象,这时候,就可以通过实现BeanFactoryAware来满足需求,代码很简单: @Servicepublic clas ...

  9. HDU 1863 畅通工程(Prim算法求解MST)

    题目: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本.现 ...

  10. bootstrap table分页,重新数据查询时页码为当前页问题

    问题描述: 使用bootstrap table时遇到一个小问题,第一次查询数据未5页,翻页到第5页后,选中条件再次查询数据时,传到后端页码仍旧为5,而此时数据量小于5页,表格显示为未查询到数据. 处理 ...