Weird problem with global variables

Weird problem with global variables

Hi,
am new to JS and I thought to start with jquery since it really make things much easier. So, i made a little script as following

function JoinNewsletter() {
      var dbTransaction = 0;

      $.ajax({
         'url':     'newsletter.php',
         'data':    {
                     'name'       : $('#name').val(),
                     'email'    : $('#email').val()
                  },
         'dataType':   'text',
         'type':      'GET',
         'success':   function(data) {
                     dbTransaction = data;
                  }
      });
      alert(dbTransaction);
      if (dbTransaction == 1) {
            
         $("#ErrorBox").show("slow");
         $('#ErrMsg').fadeIn('slow').html('Ops! Email left empty');
      }
      if (dbTransaction == 2) {
         $("#ErrorBox").show("slow");
         $('#ErrMsg').fadeIn('slow').html('Ops! Name left empty');
      }
   
}



the problem am facing is that dbTransaction is not readable outside the function. he alert is returning 0, although if i move the alert function inside the success, I see its returning 1...

i think it has to do with global variables and am not sure how to define it as global. I did some googling about it, but all I could find it that var before the variable name defines it and am not using var in my function....

any one can help me out here?

thanks,