Javascript json response undefined [duplicate] - javascript

This question already has answers here:
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
How do I return the response from an asynchronous call?
(41 answers)
Closed 5 years ago.
I have function like this:
function GetLala() {
var lala = $.getJSON(uriLala).done(function (data) {
return data;
});
return lala;
}
Then code like this:
var data = GetLala();
console.log(data.responseJSON);
This returned me undefined. If I type this code in google chrome console - then work.

Related

undefine variable Displayed when implement below code [duplicate]

This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
Closed 5 months ago.
undefine variable will loadData function from displayStructure all variables names, ages..etc displayed
async function loadData(route) {
const response = await fetch('http://127.0.0.1:8000/'+route);
const names =await response.json();
console.log(names);
return names;
}
function displayStructure(){
var names=loadNames('getNames');
var department=loadNames('getDep');
var ages=loadNames('getAge');
var bod=loadNames('getbod');
}

JavaScript and geolocation [duplicate]

This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
Closed 1 year ago.
)
So I'm trying to learn about JavaScript and geolocation, but I've run into this, probably simple, problem:
let myLat; // Global
navigator.geolocation.getCurrentPosition((position) => {
myLat = position.coords.latitude;
console.log(myLat); // works
});
console.log(myLat); // undefined
I don't get why I cannot just use a global variable to hold the latitude-info?

How to access fetch data in javascript? [duplicate]

This question already has answers here:
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
How do I return the response from an asynchronous call?
(41 answers)
Closed 2 years ago.
I am just trying to access data inside then() method.
var dataset;
fetch ('https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDPdata.json').then (response=>response.json()).then(val=>{
dataset=JSON.stringify(val.data)
});
When i console out it outside then() method it give me this:
undefined;
But when I try to console it out inside , it give me my desired result;
I just want to store my desired result in my dataset variable. How?

Get chrome storage [duplicate]

This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
Closed 4 years ago.
I want to get chrome storage.
but outside of chrome.storage.local.get function It's not working.
My code is below
chrome.storage.local.get('Setting', function(data){
var Setting = data.Setting;
});
console.log(Setting);

Accessing a variable outside of a closure [duplicate]

This question already has answers here:
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
How do I return the response from an asynchronous call?
(41 answers)
Closed 8 years ago.
I'm pretty confused by the JavaScript scoping. I have a call to FB.api (shown below) that I would like to return a response object:
(function() {
var permissions;
FB.api("/me/permissions", "get", {access_token: options.token}, function(r) {
permissions = r;
});
console.log(permissions);
})();
Ideally, I'd like to assign FB.api to a variable, and use the anonymous function to return the r component, but it appears like that's not doable.
Why is permissions undefined? Is there a way to set permissions in the parent scope?

Categories

Resources