Result of $.post call in var
Hi all,
I'm stuck on something, someone can hopefully help me out with :) I want to store the returned data from an ajax call in a variable so that I can use it later in the script. But the following code gives an error;
- $('textarea').focus(function()
- {
- var $this = $(this);
- var $id = 0;
- $.post('getid.php',{ f_id: $('select:eq(0)').val() }, function(data)
- {
- if(data==="") { alert('no good'); } else { $id = data; }
- });
- alert($id); //gives error; undefined variable
- }
What I am doing wrong...? I'm pretty sure it's something stupid but I just can't see it right now... Anyone helping out? Thanks!