I am getting back the following from an AJAX call which exactly matches the syntax in my manual:
var data = {
coach100: {
PID: '23169',
POrt: '11'
},
coach200: {
PID: '23170',
POrt: '11'
}
};
Now I want to extract one piece of data. The manual syntax is:
data.coach100.PID
but the Firebug console says: “TypeError: data.coach100 is undefined”
How to format the data in the variable “data” so that it can be extracted using dot syntax?
This runs just fine in JSfiddle – http://jsfiddle.net/GWFe9/
My guess is that you’re defining and calling data in the wrong place.
If you’re calling your data outside of the success of the ajax but also defining it there you’re going to have a bad time.
try adding var data; to the top of your doc so its a global variable – then when you get the success from ajax define your data like this –
then you can call it at any time after it’s been loaded!