Using jQuery Ajax I am able to get JSON data back from PHP end point. Now on client side I need to store the data on bigger scope level to be used with other function out the scope of Ajac done() and success() functions. so I tried to store the data in tmpdata variable like in success()
success: function (data) {tmpdata = data;  }   
and in .done()
requestdata.done(function (data) {
 tmpdata = data; 
)}
in the code of
//var tmpdata;
let tmpdata;
var requestdata = $.ajax({
...
dataType: "JSON",
success: function (data) {tmpdata = data;  }    
});
requestdata.done(function (data) {
 tmpdata = data; 
)}
function testdata(){
  console.log(tmpdata );
}
$("#data").on("click", function(){
   testdata();
 });
but I am getting this error on running testdata()
Uncaught ReferenceError: tmpdata is not defined
How can I fix this, and what is causing this?
 
    