Why the final console log is undefined?Variable time has a global scope and ajax call is async.
This is my code:
var time;
$.ajax({
async: false,
In your code, you initialize the global variable 'time' as 'data'. Where does this data variable come from? If the data variable is not global also, when you try to use console.log(time);
, it may be undefined because the data variable is undefined.
Make sure both variables are within scope to be used globally. That might work. Good luck!