I am storing the return of a function in a variable. That variable is always undefined. I have no idea why and i am hoping fresh eyes may be able to help me.
Strat Script code
function getUserInfo(data){
var params = {type:'userinfo',data:data};
$.ajax({
url: DOMAIN_NAME + "get.php",
dataType: 'text',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
data: params,
success: function( data, textStatus, jQxhr ){
var response = JSON.parse(data);
if (response.result == "success"){
console.log(response.data); //Correct Data
return response.data;
}else{
alert(response.data);
return false;
}
},
error: function( jqXhr, textStatus, errorThrown ){
alert("Something went wrong, try again later.");
return false;
}
});
}
Here , call function getUserInfo()
console.log(getUserInfo(window.localStorage.getItem("auth"))); //Undefined??
var userInfo = getUserInfo(window.localStorage.getItem("auth"));
console.log(userInfo); //Undefined??
Incase it is relevant the returned json from get.php looks like this
{"result":"success","data":"FOOBAR"}