function getRequest(url)
{
return $.ajax({
url: url,
type: "GET",
})
}
function ABC()
{
let url = "simple/url";
let response = GET.getRequest(url);
return response;
}
let global_var = "";
$.when(ABC()).then(response =>
{
global_var = response;
console.log(global_var); // -> it will show response
});
$(document).ready(function()
{
console.log(global_var); // -> empty string
});
Is there a way to pass response to global_var ?
Code in document.ready
function is executing before ajax calls, so thats why global_var
is empty string but is there any other way to deal with it ?
I can of course move whole document. ready function to $_when()
but I want to avoid it becasue code will be less readable. How to wait for global_var
assigment by response ?