I have requests on the site for the API, one of the parameters for the query is town_id
.
And the value that we substitute there is taken from LocalStorage
town_id: JSON.parse (localStorage.getItem ('town')). id
,
We put it there, automatically determining the user's location and sending the required query to the API. As a result, we get such an object
"id": 2379,
"name": "Moscow",
"region": "Moscow region",
"lat": "55.755814",
"long": "37.617635",
"update_at": 1489006800
};};
which we place in LocalStorage
.
However, if you clear the LocalStorage
and reload the page, then
console.log ((JSON.parse (localStorage.getItem ('town')))));
returns null
. And therefore there is nothing to lay in the town_id
.
More details on the video.