Reputation: 10542
Hey all Here is my code:
function SuccessOccur(data, status, req) {
if (status == "success") {
var xml = req.responseText.toString();
console.log(xml);
var jSON = $(xml).find('empResult').text();
var obj = jQuery.parseJSON(jSON);
console.log(obj.firstName);
}
}
Oddly enough I get this as a value:
undefined
If I just put this:
console.log(obj);
Then I would get all the values:
So, what am I missing?
Upvotes: 0
Views: 463
Reputation: 318162
obj
is not an object, it's an array, that's why it's in []
brackets with a 0
as the key, and a given length of 1
in the console output you've posted. Arrays are accessed like this
console.log(obj[0].firstName);
Upvotes: 5