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

228
Views
Why is undefined the ajax response value?

I have a function which returns the pictures for 2 type of devices. In function(response) i get the value correctly, then autside of $.post section the value is undefined.

function findHeadShot(key) {
          var tip;
          var ajaxUrl = "gettip.php";
          var data = { action: 'function1', azon: key};
              $.post(ajaxUrl, data, function(response) {
                  tip = response; //Here i get the response, and it is fine yet
              });
              alert(tip);         //Here the response is undefined, but why?
              switch (tip) {
                case "pc":
                   return "pc_icon.png";
                  break;

                case "server":
                   return "server_icon.png";
                  break;
              
                default:
                  return "server_icon.png";
                  break;
              }
      }
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!