好的。经过大约一个小时的尝试想不同的方法来做到这一点,我的菜鸟占了上风(这个问题将证明这一点)。
我有一个如下所示的 JSON 对象:
{
newEvent: {
Event: {
name: "Something",
timestamp: {
month: "07",
day: "27",
year: "2013",
hour: "07",
min: "42",
meridian: "pm"
},
duration: "2",
durationMeasure: "min"
}
},
msg: "Event Added"
}
它在 jquery ajax 完整回调函数中返回,因此它位于一个名为data
.
使用 Chrome,我可以console.log()
data
, data.newEvent
, data.msg
, data['newEvent']
, 和data['msg']
. 唯一返回未定义以外的任何内容data
的是(打印上面的内容)
我的问题:我在世界上如何得到任何东西data
?!任何对 JavaScript 菜鸟的见解将不胜感激!=)
编辑:代码片段:
function eventAdditionalFinish(data,textStatus) {
console.log("data: ",data,"\n");
console.log("data['newEvent']: ",data['newEvent'],"\n");
console.log("data['msg']: ",data['msg'],"\n");
console.log("data.newEvent: ",data.newEvent,"\n");
console.log("data.msg: ",data.msg,"\n");
}
Chrome 控制台的输出:
data: {"newEvent":{"Event":{"name":"Something","timestamp":{"month":"07","day":"27","year":"2013","hour":"07","min":"42","meridian":"pm"},"duration":"2","durationMeasure":"min"}},"msg":"Event Added"}
data['newEvent']: undefined
data['msg']: undefined
data.newEvent: undefined
data.msg: undefined