Possible Duplicate:
Variable doesn’t get returned from AJAX function
I have this function:
function getCompanyName(companyID) {
$.getJSON('http://www.domain.com/' + companyID + '.json', function(companyData) {
$.each(companyData, function(i,item){
result = item.name;
});
return result;
});
};
If I call it like getCompanyName(13)
the result is undefined
and if I access www.domain.com/13.json
, I get this result:
[
{
id: 13,
category_id: 2,
name: "Company Name",
phone: "333-333-3333",
address: "Address",
description: "Description",
logo_url: "/system/businesses/logos/000/000/013/thumb/G13.jpeg?1348191485"
}
]
Someone can tell me what I am doing wrong here?