【发布时间】:2020-10-28 21:53:18
【问题描述】:
我遇到了一个我无法弄清楚的奇怪行为。我浏览了许多 S/O 文档,但没有找到解决方案。任何帮助/方向将不胜感激。谢谢。
本质上,我已经将两个数组嵌套到 Ajax 调用的返回中,并且我已经确认响应包含两个数组(在 ajax/php 文件中应用了 json 编码)。但是,当我尝试使用括号属性提取元素(例如,response[0] 或 response[1])时,输出为空。
这是 Ajax 脚本和完整输出:
$.ajax({
type: "POST",
url: '/phpscripts/pass.php', //
data: {row : row},
success:(function(response){
console.log("response = " + response);
})
});
response = [[{"id":"1","learn_load":"2","start_date":"2020-06-29","target_date":"2020-10-01","completed_date":"0000-00-00","bdl_20":"Establish a mentor relationship with Jerry Murray, Director of Finance to learn how to speak their lingo.","bdl_10":"","bdl_70":"Participate in a cross-organization committee to learn how supply chain initiatives reach across business units.","cg":"Business Acumen","cg_orn":"0","cg_tit":"1","cg_lj":"0"},{"id":"2","learn_load":"3","start_date":"2020-06-29","target_date":"2020-08-10","completed_date":"0000-00-00","bdl_20":"Establish mentor relationship with Sharon Yates, Director of Logistics to learn how to enable more automated and optimized business decisions.","bdl_10":"Complete Blue Yonder online certification course.","bdl_70":"Present learning updates to leadership team upon completion of formal training.","cg":"Machine Learning\/AI training","cg_orn":"1","cg_tit":"0","cg_lj":"0"},{"id":"3","learn_load":"1","start_date":"2020-06-29","target_date":"2020-09-01","completed_date":"0000-00-00","bdl_20":"Work with a coach to rehearse presentations and other tricky interactions with senior management.","bdl_10":"","bdl_70":"Seek out opportunities to interact informally with top management (e.g., receptions, charity events, off-sites, etc.) to enhance comfort level with them when back at the workplace.\r\n\r\n","cg":"Comfort Around Higher Management","cg_orn":"0","cg_tit":"1","cg_lj":"1"},{"id":"4","learn_load":"3","start_date":"2020-06-29","target_date":"2020-08-31","completed_date":"0000-00-00","bdl_20":"Work with a coach to shift mindset from tactical project management to a focus on conceptualizing large-picture projects and foreseeing challenges and needs to be addressed.","bdl_10":"","bdl_70":"Present to analysts throughout the SCM organization tactical vs strategic project planning and how to manage the successful application of both.","cg":"Strategic Project Management","cg_orn":"1","cg_tit":"1","cg_lj":"0"},{"id":"5","learn_load":"2","start_date":"2020-07-01","target_date":"2020-07-31","completed_date":"0000-00-00","bdl_20":"Competency Explicit Mentoring for macro design. Met with Jack Barrow. ","bdl_10":"Attend Gateway Community College Excel #203 Intermediate Macro Design ","bdl_70":"Create 10 macro functions that could be used by team and provide overview at Wednesday meeting.","cg":"Excel Functions\/Macros","cg_orn":"1","cg_tit":"1","cg_lj":"0"}],[{"id":"1000001","cg":"Business Acumen","cg_orn":"0","cg_tit":"1","cg_lj":"0"},{"id":"1000002","cg":"Machine Learning\/AI training","cg_orn":"1","cg_tit":"0","cg_lj":"0"},{"id":"1000003","cg":"Comfort Around Higher Management","cg_orn":"0","cg_tit":"1","cg_lj":"1"},{"id":"1000004","cg":"Strategic Project Management","cg_orn":"1","cg_tit":"1","cg_lj":"0"},{"id":"1000005","cg":"Excel Functions\/Macros","cg_orn":"1","cg_tit":"1","cg_lj":"0"},{"id":"1000006","cg":"Written Communications (grammar\/structure)","cg_orn":"0","cg_tit":"1","cg_lj":"1"},{"id":"1000007","cg":"Leading a Team","cg_orn":"0","cg_tit":"1","cg_lj":"1"}]]
这是使用括号属性的 console.log 请求:
$.ajax({
type: "POST",
url: '/phpscripts/pass.php', //
data: {row : row},
success:(function(response){
console.log("response0 = " + response[0]);
console.log("response1 = " + response[1]);
})
});
我是新手,但我知道括号属性可以让我使用位置 0 和位置 1 隔离两个嵌套数组。我在这里缺少什么?
【问题讨论】:
-
var str = "[123]"; console.log(str[0]);