Im trying to store API return into a var
, but it´s returning undefined
when trying to log it to console, it seems to be empty.
This is the code
fetchMovies: function(city) {
var myjson;
$.getJSON('api/city?city=' + city, function(json) {
// console.debug(json);
myjson = json;
});
console.log(myjson); //
this.filmer.push(this.myjson); // Push results to div?
}
console.debug(json)
returns:
data: {91: "Nothing", 92: "Mr robot"}
name: "Stockholm"
End when access by browser the return looks like:
{
"name": "Stockholm",
"data": {
"91": "Nothing",
"92": "Mr Robot"
}
}
And the API request is http://localhost:8000/api/city?city=Stockholm
How do i store the JSON response?