Tengo una función que devuelve las imágenes para 2 tipos de dispositivos. En función (respuesta) obtengo el valor correctamente, luego fuera de la sección $.post el valor no está definido.
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; } }