I have a simple function that is consoled as such:
console.log("the state found was: " + findState());
The problem I am having is returning the found state when my findState() func is initialized. It shows fine in the console but will not return to the original initialization of findState() in the consoled output above.
I would like to use findState() in a string.
Calling the findState function
I have a javascript function with a very simple ajax request that pulls in a set json file. The json data comes back perfectly.
var foundStnew = "California";
var findState = function(){
$.ajax({
url: 'usstates.json',
type: 'get',
dataType: 'json',
success: function(data){
$(data.usstates).each(function(i,v){
if (v.abbreviation === foundStnew){
foundState(v.name);
}
});
}
});
}
function foundState(state){
var f = state;
console.log("here is the state: " + f);
return f
}
Like stated earlier, I can see the consoled result from inside the initiating functions but calling it from the originating function won't work.
How would I get the result of the function back. It always comes back undefined when i pass a value by calling findState();
Please help!