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;
}
}