Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
JS AJAX request return response
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 ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!