Hey guys I have two simple JavaScript page. One holds the function that returns the object. The other read the returned object.
Unfortunately I am unable to read the returned object.
main.js
var userObj = getUserInfo('2');
console.log(userObj); //undefined
console.log(userObj.name); //undefined
globals.js
function getUserInfo(mapID){
var jqxhr = $.ajax({
url: user_url,
type: "GET",
cache: true,
dataType: "json",
statusCode: {
404: function () {
handleError404("Error 404 at getUserInfo();")
},
500: function () {
handleError500("Error 500 at getUserInfo();")
},
},
success: function (data) {
console.log(data);
var obj = {
name: data.name,
age: data.age,
weight: data.weight
}
console.log(obj); //{name:"Kanye West", age:23, weight:"450lbs"}
return obj;
}
});
}
As you can see, If I was to output the object in the function itself, I see the result. But not if I call it from the main.js page.
Any help would be greatly appreciated!