我有以下 JSON 字符串从 PHP 5.3.10 的 json_encode 函数返回到 jQuery 1.9.1
{
"messsages":{
"error":["API_CONTROLLER.INVALID_LOGIN_PASSWORD"],
"warning":[],
"notice":[],
"success":[]
},
"result":false
}
jQuery代码:
$.ajax(targetURL, {
type: method,
data: params,
dataType: "json",
success: function(resp){
console.log(resp); //Shows object with all vars correctly displayed
//The for loop also outputs all keys and values correctly
for(var i in resp){
console.log("I: "+i);
console.log("RESP: ");
console.log(resp[i]);
}
console.log("DIRECT ACCESS");
console.log(resp.messages); //WHY undefined?
//console.log(resp.messages[error]); //undefined
//console.log(resp.messages[error][0]); //undefined
//console.log(resp.messages.error); //undefined
//console.log(resp.messages.length); //Just trying => undefined
console.log(resp.result); //this works!
//console.log(resp[messages]); //Just trying => undefined
}
});
如何访问消息?
第一个console.log 和循环显示消息存在,messages.error、messages.notice 等......也存在。但是我怎样才能访问它们?这种jQuery错误吗?