前端 ajax 获取后台json数据 解析
先贴代码
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数据 解析的更多相关文章
- 原生js,jquery通过ajax获得后台json数据动态新增页面元素
一.原生js通过ajax获取json数据 因为IE浏览器对ajax对象的创建和其他浏览器不同,为了兼容全部浏览器,我用下面的代码: function createXMLHttpRequest(){ t ...
- jq获取后台json并解析
参考: $(function () { $.ajax({ url: 'tsconfig.json', type: 'GET', dataType: 'json', timeout: 1000, cac ...
- Jquery Ajax和getJSON获取后台普通Json数据和层级Json数据解析
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java后台设计简单的json数据接口,设置可跨域访问,前端ajax获取json数据
在开发的过程中,有时候我们需要设计一个数据接口.有时候呢,数据接口和Web服务器又不在一起,所以就有跨域访问的问题. 第一步:简单的设计一个数据接口. 数据接口,听起来高大上,其实呢就是一个简单的Se ...
- jQuery AJAX获取JSON数据解析多种方式示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 用ajax获取后台数据,返回json数据,怎么在前台使用?
用ajax获取后台数据,返回json数据,怎么在前台使用呢?后台 C# code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 if (dataType == &qu ...
- 使用ajax解析后台json数据时:Unexpected token o in JSON at position 1
json数据解析异常 今天在做json数据的时候,出现了如下错误,说是解析异常. VM1584:1 Uncaught SyntaxError: Unexpected token o in JSON a ...
- 使用@RequestBody注解获取Ajax提交的json数据
最近在学习有关springMVC的知识,今天学习如何使用@RequestBody注解来获取Ajax提交的json数据内容. Ajax部分代码如下: 1 $(function(){ 2 $(" ...
- 前端学习——使用Ajax方式POST JSON数据包
0.前言 本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...
随机推荐
- 在VMware 14中安装Centos7
在VMware 14中安装Centos7 一.安装前准备 安装VMware14.1 Centos7 64位镜像下载 在VMware中安装Centos7的步骤为: 1.创建虚拟机 创建虚拟机有两种方式: ...
- rabbitmq系列三 之发布/订阅
1.发布/订阅 在上篇教程中,我们搭建了一个工作队列,每个任务只分发给一个工作者(worker).在本篇教程中,我们要做的跟之前完全不一样 —— 分发一个消息给多个消费者(consumers).这种模 ...
- 数据库MySQL(课下作业,必做)
数据库MySQL(课下作业,必做) 题目要求: 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入 ...
- 微信小程序web-view(webview) 嵌套H5页面 唤起微信支付的实现方案
场景:小程序页面有一个web-view组件,组件嵌套的H5页面,要唤起微信支付. 先讲一下我的项目,首先我是自己开发的一个H5触屏版的商城系统,里面含有购物车,订单支付等功能.然后刚开始,我们公众号里 ...
- log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.o
上面的报错是在本地java调试(windows) hadoop集群 出现的 解决方案: 在resources文件夹下面创建一个文件log4j.properties(这个其实hadoop安装目录下的 e ...
- 【树】Binary Tree Zigzag Level Order Traversal
题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...
- ES6-Set and Map
依赖文件地址 :https://github.com/chanceLe/ES6-Basic-Syntax/tree/master/js <!DOCTYPE html> <html&g ...
- CSS学习笔记(基础篇)
CSS概念 CSS 指层叠样式表 (Cascading Style Sheets)(级联样式表) Css是用来美化html标签的,相当于页面化妆. 样式表书写位置: <head> < ...
- WPF中List的Add()与Insert()方法的区别
先来看看定义: // Summary: // Adds an object to the end of the System.Collections.Generic.List<T>. // ...
- 什么是Java序列化?为什么序列化?序列化有哪些方式?
先普及一下,计算机中无法识别一个基本单元[字节]来表示,必须经过“翻译”才能让计算机理解人类的语言,这个翻译过程就是[编码],通常所说的字符转换为字节. 有I/O的地方机就会涉及编码,现在几乎所有的 ...