前端 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格式可读性更好 ...
随机推荐
- Java堆内存溢出模拟
先了解一下Java堆: 关于Java内存区域的分配,可以查看Java运行时数据区域一篇文章. Java堆是虚拟机内存管理中最大的一块区域,该区域是线程共享的,某Java进程中所有的线程都可以访问该区域 ...
- 将url动态转换成二维码插件 - 兼容IE8
插件地址 http://static.runoob.com/assets/qrcode/qrcode.min.js ,网页直接打开,然后ctrl+s保存到本地. <!DOCTYPE html& ...
- nc,远程传输文件
linux互传文件nc命令 使用nc命令可以很快的在两台主机传递文件,且不需要在同一网段,只要设置好端口即可. 一.安装(CentOS下) yum install -y nc (需要root权限 ...
- python求100以内素数
python求100以内素数之和 from math import sqrt # 使用isPrime函数 def isPrime(n): if n <= 1: return False for ...
- Visual Studio 中的 Office 和 SharePoint 开发
MSDN Library 开发工具和语言 Visual Studio 中的 Office 和 SharePoint 开发 https://msdn.microsoft.com/zh-cn/libra ...
- 第5章—构建Spring Web应用程序—SpringMVC详解
SpringMVC详解 5.1.跟踪Springmvc的请求 SpringMVC的核心流程如下: 具体步骤: 第一步:发起请求到前端控制器(DispatcherServlet) 第二步:前端控制器请求 ...
- 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 ...
- phpdocumentor生成代码注释文档(linux)
1,默认安装lnmp环境(php7),默认pear安装 2, pear channel-discover pear.phpdoc.org pear install phpdoc/phpDocume ...
- SQL中存储过程和函数的区别
转:https://www.cnblogs.com/jacketlin/p/7874009.html 本质上没区别.只是函数有如:只能返回一个变量的限制.而存储过程可以返回多个. 而函数是可以嵌入在s ...
- vue view 表单验证正常逻辑
<template> <Form ref="formInline" :model="formInline" :rules="rule ...